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
4 changes: 2 additions & 2 deletions .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 Expand Up @@ -265,4 +265,4 @@
"never"
]
}
}
}
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) {
const value = object[key];
callback(key, value, object);
}
};

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 };
25 changes: 24 additions & 1 deletion Exercises/3-wrapper.js
Original file line number Diff line number Diff line change
@@ -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 };