diff --git a/Exercises.ua.md b/Exercises.ua.md index 0e1e49b..ff8bc99 100644 --- a/Exercises.ua.md +++ b/Exercises.ua.md @@ -1,5 +1,8 @@ # Вправи +## Підняття +- Напишіть функцію, що містить в собі змінну з підняттям. + ## Скалярні типи та посилання Підготуйте дві реалізації функції `inc`: diff --git a/Exercises/1-hoisting.js b/Exercises/1-hoisting.js index 0920026..86ac68b 100644 --- a/Exercises/1-hoisting.js +++ b/Exercises/1-hoisting.js @@ -1,5 +1,8 @@ 'use strict'; -const fn = null; +const fn = () => { + console.log({ x }); + var x = 5; +}; module.exports = { fn }; diff --git a/Exercises/2-by-value.js b/Exercises/2-by-value.js index f576b24..25959d6 100644 --- a/Exercises/2-by-value.js +++ b/Exercises/2-by-value.js @@ -1,5 +1,5 @@ 'use strict'; -const inc = null; +const inc = (n) => ++n; module.exports = { inc }; diff --git a/Exercises/3-by-reference.js b/Exercises/3-by-reference.js index 74638ec..06de70f 100644 --- a/Exercises/3-by-reference.js +++ b/Exercises/3-by-reference.js @@ -1,7 +1,9 @@ 'use strict'; -const inc = (obj) => { - console.log(obj); +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..cef3d3e 100644 --- a/Exercises/4-count-types.js +++ b/Exercises/4-count-types.js @@ -1,5 +1,14 @@ 'use strict'; -const countTypesInArray = null; +const countTypesInArray = (ArrayOfTypes) => { + const countTypes = {}; + for (const item of ArrayOfTypes) { + const type = typeof item; + const count = countTypes[type] ? countTypes[type] : 0; + countTypes[type] = count + 1; + } + + return countTypes; +}; module.exports = { countTypesInArray };