2017-07-11 10:43:53 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2017-07-11 10:43:53 +00:00
|
|
|
*
|
2018-05-11 02:06:46 +00:00
|
|
|
* @format
|
2017-07-11 10:43:53 +00:00
|
|
|
* @polyfill
|
2017-07-17 10:02:14 +00:00
|
|
|
* @nolint
|
2017-07-11 10:43:53 +00:00
|
|
|
*/
|
|
|
|
|
2018-01-09 00:54:56 +00:00
|
|
|
/* eslint-disable no-bitwise, no-extend-native, radix, no-self-compare */
|
2017-07-11 10:43:53 +00:00
|
|
|
|
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex
|
|
|
|
function findIndex(predicate, context) {
|
|
|
|
if (this == null) {
|
|
|
|
throw new TypeError(
|
2018-05-11 02:06:46 +00:00
|
|
|
'Array.prototype.findIndex called on null or undefined',
|
2017-07-11 10:43:53 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
if (typeof predicate !== 'function') {
|
|
|
|
throw new TypeError('predicate must be a function');
|
|
|
|
}
|
|
|
|
var list = Object(this);
|
|
|
|
var length = list.length >>> 0;
|
|
|
|
for (var i = 0; i < length; i++) {
|
|
|
|
if (predicate.call(context, list[i], i, list)) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Array.prototype.findIndex) {
|
|
|
|
Object.defineProperty(Array.prototype, 'findIndex', {
|
|
|
|
enumerable: false,
|
|
|
|
writable: true,
|
|
|
|
configurable: true,
|
2018-05-11 02:06:46 +00:00
|
|
|
value: findIndex,
|
2017-07-11 10:43:53 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find
|
|
|
|
if (!Array.prototype.find) {
|
|
|
|
Object.defineProperty(Array.prototype, 'find', {
|
|
|
|
enumerable: false,
|
|
|
|
writable: true,
|
|
|
|
configurable: true,
|
|
|
|
value: function(predicate, context) {
|
|
|
|
if (this == null) {
|
2018-05-11 02:06:46 +00:00
|
|
|
throw new TypeError('Array.prototype.find called on null or undefined');
|
2017-07-11 10:43:53 +00:00
|
|
|
}
|
|
|
|
var index = findIndex.call(this, predicate, context);
|
|
|
|
return index === -1 ? undefined : this[index];
|
2018-05-11 02:06:46 +00:00
|
|
|
},
|
2017-07-11 10:43:53 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes
|
|
|
|
if (!Array.prototype.includes) {
|
|
|
|
Object.defineProperty(Array.prototype, 'includes', {
|
|
|
|
enumerable: false,
|
|
|
|
writable: true,
|
|
|
|
configurable: true,
|
2018-05-11 02:06:46 +00:00
|
|
|
value: function(searchElement) {
|
2017-07-11 10:43:53 +00:00
|
|
|
var O = Object(this);
|
|
|
|
var len = parseInt(O.length) || 0;
|
|
|
|
if (len === 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
var n = parseInt(arguments[1]) || 0;
|
|
|
|
var k;
|
|
|
|
if (n >= 0) {
|
|
|
|
k = n;
|
|
|
|
} else {
|
|
|
|
k = len + n;
|
|
|
|
if (k < 0) {
|
|
|
|
k = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var currentElement;
|
|
|
|
while (k < len) {
|
|
|
|
currentElement = O[k];
|
2018-05-11 02:06:46 +00:00
|
|
|
if (
|
|
|
|
searchElement === currentElement ||
|
|
|
|
(searchElement !== searchElement && currentElement !== currentElement)
|
|
|
|
) {
|
2017-07-11 10:43:53 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
k++;
|
|
|
|
}
|
|
|
|
return false;
|
2018-05-11 02:06:46 +00:00
|
|
|
},
|
2017-07-11 10:43:53 +00:00
|
|
|
});
|
|
|
|
}
|