-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathSome-Polyfill.js
More file actions
28 lines (22 loc) 路 875 Bytes
/
Copy pathSome-Polyfill.js
File metadata and controls
28 lines (22 loc) 路 875 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
/* 馃挕"JavaScript-with-JC"
馃憠Array.prototype.some and Its Polyfill
The some() method tests whether at least one element in the array passes the test implemented by the provided callback function.
馃挕Note - It does not mutate the original array, and returns a Boolean value.
馃憠 One Level Up :- We can create our own custom some( Polyfill of some ), Check out the code below.馃憞
*/
const numbers = [1, 2, 3, 4, 5, 6];
const isGreaterThan5 = (value, index, array) => {
return value > 5;
};
const result = numbers.some(isGreaterThan5);
console.log("result", result); // true
Array.prototype.customSome = function (callback) {
for (let i = 0; i < this.length; i++) {
if (callback(this[i], i, this)) {
return true;
}
}
return false;
};
const resultCustom = numbers.customSome(isGreaterThan5);
console.log("resultCustom", resultCustom); // true