From 2c8ff0f1e5f15fe038fe818f385d67fb8c27c680 Mon Sep 17 00:00:00 2001 From: dimasta Date: Tue, 21 Jul 2020 06:25:37 +0500 Subject: [PATCH 1/2] done with exs --- Exercises/1-hoisting.js | 5 ++++- Exercises/2-by-value.js | 2 +- Exercises/3-by-reference.js | 6 +++++- Exercises/4-count-types.js | 12 +++++++++++- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/Exercises/1-hoisting.js b/Exercises/1-hoisting.js index 0920026..0a66328 100644 --- a/Exercises/1-hoisting.js +++ b/Exercises/1-hoisting.js @@ -1,5 +1,8 @@ 'use strict'; -const fn = null; +const fn = () => { + console.log({ a }); + var a = 5; +}; module.exports = { fn }; diff --git a/Exercises/2-by-value.js b/Exercises/2-by-value.js index f576b24..e7652d5 100644 --- a/Exercises/2-by-value.js +++ b/Exercises/2-by-value.js @@ -1,5 +1,5 @@ 'use strict'; -const inc = null; +const inc = a => ++a; module.exports = { inc }; diff --git a/Exercises/3-by-reference.js b/Exercises/3-by-reference.js index f576b24..be65287 100644 --- a/Exercises/3-by-reference.js +++ b/Exercises/3-by-reference.js @@ -1,5 +1,9 @@ 'use strict'; -const inc = null; +const inc = num => { + if (typeof num === 'object') { + ++num.n; + } +}; module.exports = { inc }; diff --git a/Exercises/4-count-types.js b/Exercises/4-count-types.js index 4c9545a..2f0d34a 100644 --- a/Exercises/4-count-types.js +++ b/Exercises/4-count-types.js @@ -1,5 +1,15 @@ 'use strict'; -const countTypesInArray = null; +const array = [true, 'hello', 5, 12, -200, false, false, 'word']; + +const countTypesInArray = array => { + const obj = {}; + array.forEach(item => { + const type = typeof item; + const count = obj[type] || 0; + obj[type] = count + 1; + }); + return obj; +}; module.exports = { countTypesInArray }; From f3e0a8bf836f81143f195bbd5c69c4ee10e84843 Mon Sep 17 00:00:00 2001 From: dimasta Date: Tue, 21 Jul 2020 22:34:24 +0500 Subject: [PATCH 2/2] clean code --- Exercises/1-hoisting.js | 3 +-- Exercises/4-count-types.js | 2 -- package-lock.json | 2 +- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Exercises/1-hoisting.js b/Exercises/1-hoisting.js index 0a66328..7a69046 100644 --- a/Exercises/1-hoisting.js +++ b/Exercises/1-hoisting.js @@ -1,8 +1,7 @@ 'use strict'; const fn = () => { - console.log({ a }); - var a = 5; + const a = 5; }; module.exports = { fn }; diff --git a/Exercises/4-count-types.js b/Exercises/4-count-types.js index 2f0d34a..b67b373 100644 --- a/Exercises/4-count-types.js +++ b/Exercises/4-count-types.js @@ -1,7 +1,5 @@ 'use strict'; -const array = [true, 'hello', 5, 12, -200, false, false, 'word']; - const countTypesInArray = array => { const obj = {}; array.forEach(item => { diff --git a/package-lock.json b/package-lock.json index 33eaeb2..f235cea 100644 --- a/package-lock.json +++ b/package-lock.json @@ -576,7 +576,7 @@ "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", "requires": { - "minimist": "1.2.5" + "minimist": "0.0.8" }, "dependencies": { "minimist": {