diff --git a/.eslintrc.json b/.eslintrc.json index 188baf7..9b0f412 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -18,7 +18,7 @@ ], "linebreak-style": [ "error", - "unix" + "windows" ], "quotes": [ "error", @@ -265,4 +265,4 @@ "never" ] } -} +} \ No newline at end of file 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..8cbbe9c 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..8f8f4f5 100644 --- a/Exercises/3-wrapper.js +++ b/Exercises/3-wrapper.js @@ -1,5 +1,28 @@ 'use strict'; -const contract = (fn, ...types) => null; +const contract = (fn, ...types) => (...args) => { + for (let i = 0; i < args.length; i++) { + const type = types[i].name; + const argType = typeof args[i]; + if (type.toLowerCase() !== argType) { + throw new TypeError( + `Expected argument type "${type}"` + ); + } + } + + const res = fn(...args); + const resType = typeof res; + const lastType = types[types.length - 1].name; + + if (resType !== lastType.toLowerCase()) { + throw new TypeError( + `Expected result type "${lastType}"` + ); + } + + return res; +}; + module.exports = { contract };
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: