From 4fae9ceea449cab3920947a5bd75755dd00e4ada Mon Sep 17 00:00:00 2001 From: Destaby <53400745+Destaby@users.noreply.github.com> Date: Mon, 16 Dec 2019 04:08:53 +0200 Subject: [PATCH 01/10] Update 1-callback.js --- Exercises/1-callback.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Exercises/1-callback.js b/Exercises/1-callback.js index 8270a12..ad0adbc 100644 --- a/Exercises/1-callback.js +++ b/Exercises/1-callback.js @@ -1,5 +1,14 @@ 'use strict'; -const iterate = (obj, callback) => null; +const iterate = (obj, callback) => { + if (!obj) { + callback(new Error('obj needed')); + return; + } + for (const key in obj) { + callback(key, obj[key], obj); + } + return; +}; module.exports = { iterate }; From 78ef473a318aac3c6fb13cfd63a6cc6d8b603bc1 Mon Sep 17 00:00:00 2001 From: Destaby <53400745+Destaby@users.noreply.github.com> Date: Mon, 16 Dec 2019 04:09:31 +0200 Subject: [PATCH 02/10] Update 2-closure.js --- Exercises/2-closure.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Exercises/2-closure.js b/Exercises/2-closure.js index 0f07103..db0c011 100644 --- a/Exercises/2-closure.js +++ b/Exercises/2-closure.js @@ -1,5 +1,6 @@ 'use strict'; -const store = x => null; +const store = x => () => x; module.exports = { store }; + From c2e962994d0f9e857bb9cd56fc25d30f8a8251da Mon Sep 17 00:00:00 2001 From: Destaby <53400745+Destaby@users.noreply.github.com> Date: Mon, 16 Dec 2019 04:09:54 +0200 Subject: [PATCH 03/10] Update 3-wrapper.js --- Exercises/3-wrapper.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Exercises/3-wrapper.js b/Exercises/3-wrapper.js index fb7207e..935969c 100644 --- a/Exercises/3-wrapper.js +++ b/Exercises/3-wrapper.js @@ -1,5 +1,13 @@ 'use strict'; -const contract = (fn, ...types) => null; +const contract = (fn, ...types) => (...arr) => { + for (let i = 1; i < types.length - 1; i++) { + if (typeof fn(...arr) !== types[i].name.toLowerCase()) { + throw new TypeError('Types are different'); + } + } + return fn(...arr); +}; module.exports = { contract }; + From c0d9e7a28d134d30049ec0e74c3866a63314f0a8 Mon Sep 17 00:00:00 2001 From: Destaby <53400745+Destaby@users.noreply.github.com> Date: Mon, 16 Dec 2019 20:26:43 +0200 Subject: [PATCH 04/10] Update 1-callback.js --- Exercises/1-callback.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Exercises/1-callback.js b/Exercises/1-callback.js index ad0adbc..69c423c 100644 --- a/Exercises/1-callback.js +++ b/Exercises/1-callback.js @@ -5,10 +5,11 @@ const iterate = (obj, callback) => { callback(new Error('obj needed')); return; } - for (const key in obj) { + for (const key of Object.keys(obj)) { callback(key, obj[key], obj); } return; }; module.exports = { iterate }; + From 2af4528024ae7e8530f20233cadbd79c66282b34 Mon Sep 17 00:00:00 2001 From: Destaby <53400745+Destaby@users.noreply.github.com> Date: Mon, 16 Dec 2019 20:27:51 +0200 Subject: [PATCH 05/10] Update 3-wrapper.js --- Exercises/3-wrapper.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Exercises/3-wrapper.js b/Exercises/3-wrapper.js index 935969c..5d7633f 100644 --- a/Exercises/3-wrapper.js +++ b/Exercises/3-wrapper.js @@ -1,8 +1,15 @@ 'use strict'; const contract = (fn, ...types) => (...arr) => { - for (let i = 1; i < types.length - 1; i++) { - if (typeof fn(...arr) !== types[i].name.toLowerCase()) { + const resultType = typeof fn(...arr); + const neededReType = types[types.length - 1].name.toLowerCase(); + for (let i = 0; i < types.length - 1; i++) { + const argType = typeof arr[i]; + const neededArgType = types[i].name.toLowerCase(); + if (argType !== neededArgType) { + throw new TypeError('Types are different'); + } + if (resultType !== neededReType) { throw new TypeError('Types are different'); } } @@ -11,3 +18,4 @@ const contract = (fn, ...types) => (...arr) => { module.exports = { contract }; + From e7fef1a6586e79d8ceb270e79d9155a444723e0d Mon Sep 17 00:00:00 2001 From: Destaby <53400745+Destaby@users.noreply.github.com> Date: Mon, 16 Dec 2019 22:15:48 +0200 Subject: [PATCH 06/10] Update 3-wrapper.js --- Exercises/3-wrapper.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Exercises/3-wrapper.js b/Exercises/3-wrapper.js index 5d7633f..d87b74c 100644 --- a/Exercises/3-wrapper.js +++ b/Exercises/3-wrapper.js @@ -3,15 +3,15 @@ const contract = (fn, ...types) => (...arr) => { const resultType = typeof fn(...arr); const neededReType = types[types.length - 1].name.toLowerCase(); + if (resultType !== neededReType) { + throw new TypeError('Types are different'); + } for (let i = 0; i < types.length - 1; i++) { const argType = typeof arr[i]; const neededArgType = types[i].name.toLowerCase(); if (argType !== neededArgType) { throw new TypeError('Types are different'); } - if (resultType !== neededReType) { - throw new TypeError('Types are different'); - } } return fn(...arr); }; From 17aeeb02000138b5cb9d5fd671bb8645364615e0 Mon Sep 17 00:00:00 2001 From: Destaby <53400745+Destaby@users.noreply.github.com> Date: Mon, 16 Dec 2019 22:23:36 +0200 Subject: [PATCH 07/10] Update 3-wrapper.js --- Exercises/3-wrapper.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Exercises/3-wrapper.js b/Exercises/3-wrapper.js index d87b74c..460dc40 100644 --- a/Exercises/3-wrapper.js +++ b/Exercises/3-wrapper.js @@ -1,11 +1,6 @@ 'use strict'; const contract = (fn, ...types) => (...arr) => { - const resultType = typeof fn(...arr); - const neededReType = types[types.length - 1].name.toLowerCase(); - if (resultType !== neededReType) { - throw new TypeError('Types are different'); - } for (let i = 0; i < types.length - 1; i++) { const argType = typeof arr[i]; const neededArgType = types[i].name.toLowerCase(); @@ -13,9 +8,15 @@ const contract = (fn, ...types) => (...arr) => { throw new TypeError('Types are different'); } } - return fn(...arr); + const neededReType = types[types.length - 1].name.toLowerCase(); + const result = fn(...arr); + if (typeof result !== neededReType) { + throw new TypeError('Types are different'); + } + return result; }; module.exports = { contract }; + From f8cbfc80a7a9a55d37d768070edf9c67af043a87 Mon Sep 17 00:00:00 2001 From: Destaby <53400745+Destaby@users.noreply.github.com> Date: Mon, 16 Dec 2019 22:28:15 +0200 Subject: [PATCH 08/10] Update 3-wrapper.js --- Exercises/3-wrapper.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/Exercises/3-wrapper.js b/Exercises/3-wrapper.js index 460dc40..18d4889 100644 --- a/Exercises/3-wrapper.js +++ b/Exercises/3-wrapper.js @@ -17,6 +17,3 @@ const contract = (fn, ...types) => (...arr) => { }; module.exports = { contract }; - - - From 6eb04e3e257f46ef920309b6943bfe620c2fc8be Mon Sep 17 00:00:00 2001 From: Destaby <53400745+Destaby@users.noreply.github.com> Date: Mon, 16 Dec 2019 22:32:58 +0200 Subject: [PATCH 09/10] Update 3-wrapper.js --- Exercises/3-wrapper.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Exercises/3-wrapper.js b/Exercises/3-wrapper.js index 18d4889..8e43226 100644 --- a/Exercises/3-wrapper.js +++ b/Exercises/3-wrapper.js @@ -17,3 +17,4 @@ const contract = (fn, ...types) => (...arr) => { }; module.exports = { contract }; + From 1fc193e84fb7d9ac8747ece5d86601b9ab8d5d12 Mon Sep 17 00:00:00 2001 From: Destaby <53400745+Destaby@users.noreply.github.com> Date: Mon, 16 Dec 2019 22:37:48 +0200 Subject: [PATCH 10/10] Update 3-wrapper.js --- Exercises/3-wrapper.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Exercises/3-wrapper.js b/Exercises/3-wrapper.js index 8e43226..789970e 100644 --- a/Exercises/3-wrapper.js +++ b/Exercises/3-wrapper.js @@ -11,10 +11,9 @@ const contract = (fn, ...types) => (...arr) => { const neededReType = types[types.length - 1].name.toLowerCase(); const result = fn(...arr); if (typeof result !== neededReType) { - throw new TypeError('Types are different'); - } + throw new TypeError('Types are different'); + } return result; }; module.exports = { contract }; - pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy