-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
87 lines (69 loc) · 1.7 KB
/
test.js
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// -------------------native filter function
const samFilter = [1,2,3]
samFilter.map(showArra);
function calle (number, index) {
if (2 === index) return false;
else return true;
}
const newArr = samFilter.filter(calle);
console.log("-------------------");
function showArra(number, index) {
console.log(number, index);
}
newArr.map(showArra);
class Array {
filter (callback) {
const arra = [];
for(let i = 0; index < this.length; i++) {
const ans = callback(this[i], i);
if(ans === true) {
arra.push(this[i]);
}
}
return arra;
}
}
// ----------------------
// ------------------------native find function
const sam = [1,2,3];
function findNumber (number, index) {
if (index === 2) return true;
else return false;
}
const newArra = sam.find(findNumber);
console.log(newArra);
class Array {
findilter (callback) {
for(let i = 0; i < this.length; i++) {
const ans = callback(this[i], i);
if(ans === true) {
return (
this[i]
);
}
}
}
}
// ----------------------------------------------
// -----------------native map function
const sMap = [1,2,3];
function mapCallback(number, index) {
console.log(number,' ', index);
const x = 10;
return(
"iqbal is awsome"
);
}
const returned = sMap.map(mapCallback);
console.log(returned);
class Array {
arra = [];
map(callback) {
for (index = 0; index < this.lenght; index++) {
const one = callback(this[index], index);
arra.push(one);
}
return arra;
}
}
// -------------------