From 521071b516536d71e16160217ca6f1a7e48025bb Mon Sep 17 00:00:00 2001 From: beliy-a Date: Wed, 10 Mar 2021 21:33:37 +0300 Subject: [PATCH 1/2] change linebreak-style --- .eslintrc.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From f354692b6994bbe707abaeb4d8ce0dd7c729881c Mon Sep 17 00:00:00 2001 From: beliy-a Date: Wed, 10 Mar 2021 21:34:12 +0300 Subject: [PATCH 2/2] add solving for all tasks --- Exercises/1-callback.js | 7 ++++++- Exercises/2-closure.js | 3 ++- Exercises/3-wrapper.js | 25 ++++++++++++++++++++++++- 3 files changed, 32 insertions(+), 3 deletions(-) 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 };