diff --git a/Exercises/1-callback.js b/Exercises/1-callback.js index 8270a12..ccde3b3 100644 --- a/Exercises/1-callback.js +++ b/Exercises/1-callback.js @@ -1,5 +1,10 @@ 'use strict'; -const iterate = (obj, callback) => null; +const iterate = (object, callback) => { + for (const key in object) { + const value = object[key]; + callback(key, value, object); + } +}; module.exports = { iterate }; diff --git a/Exercises/2-closure.js b/Exercises/2-closure.js index 0f07103..7b71264 100644 --- a/Exercises/2-closure.js +++ b/Exercises/2-closure.js @@ -1,5 +1,5 @@ '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..fd1441b 100644 --- a/Exercises/3-wrapper.js +++ b/Exercises/3-wrapper.js @@ -1,5 +1,24 @@ 'use strict'; -const contract = (fn, ...types) => null; +const contract = (fn, ...types) => (...args) => { + args.forEach((arg, index) => { + const typeName = types[index].name.toLowerCase(); + const argType = typeof arg; + if (typeName !== argType) { + throw new TypeError(`Argument type expected: + ${typeName}, got: ${argType}`); + } + }); + const result = fn(...args); + const expectedResultType = types[types.length - 1].name.toLowerCase(); + const resultType = typeof result; + + if (expectedResultType !== resultType) { + throw new TypeError(`Result type expected: + ${expectedResultType}, got: ${resultType}`); + } + + 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