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

const contract = (fn, ...types) => null;
const contract = (fn, ...types) => (...args) => {
let i = 0;
for (const val of args) {
const Type = types[i++];
const temp = new Type();
const type = typeof temp.valueOf();
if (typeof val !== type) {
throw new TypeError(`Неверный тип аргумента ${val}`);
}
}
const res = fn(...args);
const TypeRes = types[types.length - 1];
const tempRes = new TypeRes();
const typeRes = typeof tempRes.valueOf();
if (typeof res !== typeRes) {
throw new TypeError(`Неверный тип результата ${res}`);
}
return res;
};

module.exports = { contract };