-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask.js
More file actions
29 lines (23 loc) · 686 Bytes
/
task.js
File metadata and controls
29 lines (23 loc) · 686 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
Array.prototype.CustomeMap = function(func){
const result = [];
for (let i = 0; i < this.length; index++) {
func(this[index], index, this);
}
return result
}
Array.prototype.CustomeFilter = function (func) {
let filtered = [];
for(let i = 0; i < this.length; i++) {
if (func(this[i], i, this)) filtered.push(this[i]);
}
return filtered;
};
Array.prototype.CustomeReduce = function (arr, initialValue, reducer) {
if(arr.length === 0) {
return initialValue;
} else {
const [first, ...rest] = arr;
const updatedAcc = reducer(initialValue, first);
return myReduce(rest, updatedAcc, reducer);
}
}