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.
31 lines
851 B
31 lines
851 B
'use strict'; |
|
|
|
var ES = require('es-abstract/es6'); |
|
var $isNaN = Number.isNaN || function isNaN(a) { |
|
return a !== a; |
|
}; |
|
var $isFinite = Number.isFinite || function isFinite(n) { |
|
return typeof n === 'number' && global.isFinite(n); |
|
}; |
|
var indexOf = Array.prototype.indexOf; |
|
|
|
module.exports = function includes(searchElement) { |
|
var fromIndex = arguments.length > 1 ? ES.ToInteger(arguments[1]) : 0; |
|
if (indexOf && !$isNaN(searchElement) && $isFinite(fromIndex) && typeof searchElement !== 'undefined') { |
|
return indexOf.apply(this, arguments) > -1; |
|
} |
|
|
|
var O = ES.ToObject(this); |
|
var length = ES.ToLength(O.length); |
|
if (length === 0) { |
|
return false; |
|
} |
|
var k = fromIndex >= 0 ? fromIndex : Math.max(0, length + fromIndex); |
|
while (k < length) { |
|
if (ES.SameValueZero(searchElement, O[k])) { |
|
return true; |
|
} |
|
k += 1; |
|
} |
|
return false; |
|
};
|
|
|