polyfill-service
Version:
A polyfill combinator
21 lines (16 loc) • 565 B
JavaScript
Array.prototype.lastIndexOf = function lastIndexOf(searchElement) {
if (this === undefined || this === null) {
throw new TypeError(this + ' is not an object');
}
var
arraylike = this instanceof String ? this.split('') : this,
length = Math.max(Math.min(arraylike.length, 9007199254740991), 0) || 0,
index = Number(arguments[1]) || 0;
index = 1 in arguments ? (index < 0 ? Math.max(length + index, 0) : index) + 1 : length;
while (--index >= 0) {
if (index in arraylike && arraylike[index] === searchElement) {
return index;
}
}
return -1;
};