From fc6d9b228ba95e1e820f43b4a1e0d2e08f8240e7 Mon Sep 17 00:00:00 2001 From: hok7z Date: Wed, 27 Nov 2024 15:18:02 +0200 Subject: [PATCH 1/3] First commit --- 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, 20 insertions(+), 5 deletions(-) diff --git a/Exercises/1-hoisting.js b/Exercises/1-hoisting.js index 09200261..86ac68b1 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 f576b24e..25959d68 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 74638ecd..06de70f9 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 4c9545af..9d12ad00 100644 --- a/Exercises/4-count-types.js +++ b/Exercises/4-count-types.js @@ -1,5 +1,15 @@ 'use strict'; -const countTypesInArray = null; +const countTypesInArray = (ArrayOfTypes) => { + const countTypes = {}; + for (const item of ArrayOfTypes) { + const type = typeof item; + let count = countTypes[type]; + count = count ? count++ : count = 0; + countTypes[type] = count; + }; + + return countTypes; +}; module.exports = { countTypesInArray }; From 60e0436bf8d467b5dc46adb5a2e80453fa9ea06b Mon Sep 17 00:00:00 2001 From: hok7z Date: Wed, 27 Nov 2024 15:24:08 +0200 Subject: [PATCH 2/3] Add hoisting to Exercises.ua.md --- Exercises.ua.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Exercises.ua.md b/Exercises.ua.md index 0e1e49b1..ff8bc992 100644 --- a/Exercises.ua.md +++ b/Exercises.ua.md @@ -1,5 +1,8 @@ # Вправи +## Підняття +- Напишіть функцію, що містить в собі змінну з підняттям. + ## Скалярні типи та посилання Підготуйте дві реалізації функції `inc`: From 91231286d9e9b1967a4769e6c663b3579b699644 Mon Sep 17 00:00:00 2001 From: hok7z Date: Wed, 27 Nov 2024 17:33:48 +0200 Subject: [PATCH 3/3] Fix countTypesInArray --- Exercises/4-count-types.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Exercises/4-count-types.js b/Exercises/4-count-types.js index 9d12ad00..cef3d3e4 100644 --- a/Exercises/4-count-types.js +++ b/Exercises/4-count-types.js @@ -4,10 +4,9 @@ const countTypesInArray = (ArrayOfTypes) => { const countTypes = {}; for (const item of ArrayOfTypes) { const type = typeof item; - let count = countTypes[type]; - count = count ? count++ : count = 0; - countTypes[type] = count; - }; + const count = countTypes[type] ? countTypes[type] : 0; + countTypes[type] = count + 1; + } return countTypes; };