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
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 value = obj[key];
callback(key, value, 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 };
19 changes: 18 additions & 1 deletion Exercises/3-wrapper.js
Original file line number Diff line number Diff line change
@@ -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 };
3 changes: 1 addition & 2 deletions JavaScript/1-math.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

const { sin } = Math;
const π = Math.PI;
const { sin, PI: π } = Math;

const inverse = f => x => 1 / f(x);

Expand Down