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
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
],
"linebreak-style": [
"error",
"unix"
"windows"
],
"quotes": [
"error",
Expand Down
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 = (obj, callback) => {
for (const field in obj) {
const value = obj[field];
callback(field, value, obj);
}
};

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

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


module.exports = { store };
18 changes: 17 additions & 1 deletion Exercises/3-wrapper.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
'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 type = types[i];
const name = type.name.toLowerCase();
if (typeof(arg) !== name) {
throw new TypeError(`Argument expected to be ${name}`);
}
}
const res = fn(...args);
const typeOfRes = types[types.length - 1];
const name = typeOfRes.name.toLowerCase();
if (typeof(res) !== name) {
throw new TypeError(`Result expected to be ${name}`);
}
return res;
};

module.exports = { contract };
Loading