You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.4 KiB
54 lines
1.4 KiB
if (!Array.prototype.findIndex) { |
|
Object.defineProperty(Array.prototype, 'findIndex', { |
|
value: function(predicate) { |
|
'use strict'; |
|
if (this == null) { |
|
throw new TypeError('Array.prototype.findIndex called on null or undefined'); |
|
} |
|
if (typeof predicate !== 'function') { |
|
throw new TypeError('predicate must be a function'); |
|
} |
|
var list = Object(this); |
|
var length = list.length >>> 0; |
|
var thisArg = arguments[1]; |
|
var value; |
|
|
|
for (var i = 0; i < length; i++) { |
|
value = list[i]; |
|
if (predicate.call(thisArg, value, i, list)) { |
|
return i; |
|
} |
|
} |
|
return -1; |
|
}, |
|
enumerable: false, |
|
configurable: false, |
|
writable: false |
|
}); |
|
} |
|
|
|
if (!Array.prototype.find) { |
|
Object.defineProperty(Array.prototype, 'find', { |
|
value: function(predicate) { |
|
'use strict'; |
|
if (this == null) { |
|
throw new TypeError('Array.prototype.find called on null or undefined'); |
|
} |
|
if (typeof predicate !== 'function') { |
|
throw new TypeError('predicate must be a function'); |
|
} |
|
var list = Object(this); |
|
var length = list.length >>> 0; |
|
var thisArg = arguments[1]; |
|
var value; |
|
|
|
for (var i = 0; i < length; i++) { |
|
value = list[i]; |
|
if (predicate.call(thisArg, value, i, list)) { |
|
return value; |
|
} |
|
} |
|
return undefined; |
|
} |
|
}); |
|
}
|
|
|