Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Exercises/1-callback.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
'use strict';

const iterate = (obj, callback) => null;
const iterate = (object, callback) => {
for (const key in object) {
if (Object.prototype.hasOwnProperty.call(object, key))
callback(key, object[key], object);
}
};

module.exports = { iterate };
2 changes: 1 addition & 1 deletion Exercises/2-closure.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';

const store = x => null;
const store = x => () => x;

module.exports = { store };
16 changes: 15 additions & 1 deletion Exercises/3-wrapper.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
'use strict';

const contract = (fn, ...types) => null;
const contract = (fn, ...types) => (...args) => {
for (const index in args) {
const arg = args[index];
if (arg !== types[index](arg)) throw new TypeError(
`type of argument '${arg}': '${typeof arg}'
does not match '${types[index]}'!`);
}
const res = fn(...args);
if (res !== types[types.length - 1](res))
throw new TypeError(
`type of result '${res}': '${typeof res}'
does not match '${types[types.length - 1]}'!`
);
return res;
};

module.exports = { contract };