diff --git a/Exercises/1-callback.js b/Exercises/1-callback.js index 8270a12..69c423c 100644 --- a/Exercises/1-callback.js +++ b/Exercises/1-callback.js @@ -1,5 +1,15 @@ 'use strict'; -const iterate = (obj, callback) => null; +const iterate = (obj, callback) => { + if (!obj) { + callback(new Error('obj needed')); + return; + } + for (const key of Object.keys(obj)) { + callback(key, obj[key], obj); + } + return; +}; module.exports = { iterate }; + 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 }; + diff --git a/Exercises/3-wrapper.js b/Exercises/3-wrapper.js index fb7207e..789970e 100644 --- a/Exercises/3-wrapper.js +++ b/Exercises/3-wrapper.js @@ -1,5 +1,19 @@ 'use strict'; -const contract = (fn, ...types) => null; +const contract = (fn, ...types) => (...arr) => { + 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'); + } + } + 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 }; 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