Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
11 changes: 10 additions & 1 deletion Exercises/1-callback.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
'use strict';

const iterate = (obj, callback) => null;
const iterate = (obj, callback) => {
if (!obj) {
callback(new Error('obj needed'));
return;
}
for (const key in obj) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will iterate all object keys plus inherited keys from prototype chain.

callback(key, obj[key], obj);
}
return;
};

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 };

10 changes: 9 additions & 1 deletion Exercises/3-wrapper.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
'use strict';

const contract = (fn, ...types) => null;
const contract = (fn, ...types) => (...arr) => {
for (let i = 1; i < types.length - 1; i++) {
if (typeof fn(...arr) !== types[i].name.toLowerCase()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use intermediate variables

throw new TypeError('Types are different');
}
}
return fn(...arr);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check result type

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last argument is a result type.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check result type after calling fn

};

module.exports = { contract };