-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjs_lesson.js
More file actions
42 lines (35 loc) · 831 Bytes
/
js_lesson.js
File metadata and controls
42 lines (35 loc) · 831 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
function sequence(start = 0, step = 1) {
let startCount = start;
return function () {
let returnValue = startCount;
startCount += step;
return returnValue;
};
}
function take(fn, count) {
let result = [];
for (let i = 0; i < count; i++) {
result = [...result, fn()];
}
return result;
}
function map(fn, array) {
return array.map((el) => fn(el));
}
//you need to write your own map and filter , don't use existing!
function bind(fn, context) {
return function (...args) {
return fn.call(context, ...args);
};
}
function pluck(objects, fieldName) {
let result = [];
objects.forEach((el) => (result = [...result, el[fieldName]]));
return result;
}
function filter(arr, fn) {
return arr.filter((el) => fn(el) === true);
}
function count(obj) {
return Object.keys(obj).length;
}