From b09cc6a74798e46e40520716c91cb35b97177205 Mon Sep 17 00:00:00 2001 From: Katywolk Date: Thu, 30 Jan 2025 12:53:17 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=D0=B0=203=20=D1=80=D0=B5=D1=88=D0=B5=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=B4=D0=B0=D1=87=20DataTypes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Exercises/1-hoisting.js | 5 ++++- Exercises/2-by-value.js | 6 +++++- Exercises/3-by-reference.js | 12 ++++++++++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Exercises/1-hoisting.js b/Exercises/1-hoisting.js index 0920026..ab6ab6b 100644 --- a/Exercises/1-hoisting.js +++ b/Exercises/1-hoisting.js @@ -1,5 +1,8 @@ 'use strict'; -const fn = null; +const fn = function raising() { + const variable = 'Hello'; + console.log(variable); +}; module.exports = { fn }; diff --git a/Exercises/2-by-value.js b/Exercises/2-by-value.js index f576b24..80e623e 100644 --- a/Exercises/2-by-value.js +++ b/Exercises/2-by-value.js @@ -1,5 +1,9 @@ 'use strict'; -const inc = null; +const inc = (x) => ++x; + +// function inc(n) { +// return n+1; +// } module.exports = { inc }; diff --git a/Exercises/3-by-reference.js b/Exercises/3-by-reference.js index 74638ec..c7e21a3 100644 --- a/Exercises/3-by-reference.js +++ b/Exercises/3-by-reference.js @@ -1,7 +1,15 @@ 'use strict'; -const inc = (obj) => { - console.log(obj); +const inc = function(obj) { + obj.n += 1; }; +// function inc(num) { +// if (num && typeof num.n === 'number') { +// num.n += 1; +// } else { +// throw new Error("Invalid input: Object must have a numeric 'n' field"); +// } +// } + module.exports = { inc }; From afbdd3b6057288b260a765fa465f6cb1fc964022 Mon Sep 17 00:00:00 2001 From: Katywolk Date: Thu, 30 Jan 2025 13:49:52 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=D0=B0=20=D1=80=D0=B5=D1=88=D0=B5=D0=BD=D0=B8=D0=B5=204=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=B4=D0=B0=D1=87=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Exercises/4-count-types.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Exercises/4-count-types.js b/Exercises/4-count-types.js index 4c9545a..ff1faae 100644 --- a/Exercises/4-count-types.js +++ b/Exercises/4-count-types.js @@ -1,5 +1,12 @@ 'use strict'; -const countTypesInArray = null; +function countTypesInArray(arr) { + const result = {}; + for (const item of arr) { + const type = typeof item; + result[type] = (result[type] || 0) + 1; + } + return result; +} module.exports = { countTypesInArray };