diff --git a/Exercises/1-callback.js b/Exercises/1-callback.js index 8270a12..808648c 100644 --- a/Exercises/1-callback.js +++ b/Exercises/1-callback.js @@ -1,5 +1,11 @@ 'use strict'; -const iterate = (obj, callback) => null; +const iterate = (obj, callback) => { + const keys = Object.keys(obj); + for (const key of keys) { + const value = obj[key]; + callback(key, value, obj); + } +}; 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..96602ef 100644 --- a/Exercises/3-wrapper.js +++ b/Exercises/3-wrapper.js @@ -1,5 +1,22 @@ 'use strict'; -const contract = (fn, ...types) => null; +const contract = (fn, ...types) => (...args) => { + + for (let i = 0; i < types.length - 1; i++) { + const arg = args[i]; + const curType = types[i].name.toLowerCase(); + + if (typeof arg !== curType) { + throw TypeError(`argument ${args[i]} is not a ${types[i].name}`); + } + } + + const result = fn(...args); + const resultType = types[types.length - 1].name.toLowerCase(); + if (typeof result !== resultType) { + throw TypeError(`result ${result} is not a ${resultType}`); + } + return result; +}; module.exports = { contract }; diff --git a/JavaScript/1-math.js b/JavaScript/1-math.js index 0b8ae4d..5268847 100644 --- a/JavaScript/1-math.js +++ b/JavaScript/1-math.js @@ -1,7 +1,6 @@ 'use strict'; -const { sin } = Math; -const π = Math.PI; +const { sin, PI: π } = Math; const inverse = f => x => 1 / f(x); 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