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
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
node_modules/
Exercises/
7 changes: 7 additions & 0 deletions Exercises/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"trailingComma": "es5",
"tabWidth": 2,
"semi": true,
"singleQuote": true,
"space-before-function-paren": ["error", "never"]
}
8 changes: 7 additions & 1 deletion Exercises/1-callback.js
Original file line number Diff line number Diff line change
@@ -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 element = obj[key];
callback(key, element, obj);
}
};

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 };
20 changes: 19 additions & 1 deletion Exercises/3-wrapper.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
'use strict';
// prettier-ignore
const contract =
(fn, ...types) =>
(...args) => {
for (let i = 0; i < args; i++) {
const type = types[i];
const arg = args[i];
if (typeof arg !== type.name.toLowerCase()) {
throw new TypeError('Types do not match');
}
}

const contract = (fn, ...types) => null;
const result = fn(...args);
const type = types.at(-1);
if (typeof result !== type.name.toLowerCase()) {
throw new TypeError('Types do not match');
}

return result;
};

module.exports = { contract };
Loading