mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-24 09:25:15 +00:00
27 lines
1.2 KiB
JavaScript
27 lines
1.2 KiB
JavaScript
|
'use strict';
|
||
|
/* eslint-disable es/no-array-prototype-lastindexof -- safe */
|
||
|
var toIndexedObject = require('../internals/to-indexed-object');
|
||
|
var toInteger = require('../internals/to-integer');
|
||
|
var toLength = require('../internals/to-length');
|
||
|
var arrayMethodIsStrict = require('../internals/array-method-is-strict');
|
||
|
|
||
|
var min = Math.min;
|
||
|
var $lastIndexOf = [].lastIndexOf;
|
||
|
var NEGATIVE_ZERO = !!$lastIndexOf && 1 / [1].lastIndexOf(1, -0) < 0;
|
||
|
var STRICT_METHOD = arrayMethodIsStrict('lastIndexOf');
|
||
|
var FORCED = NEGATIVE_ZERO || !STRICT_METHOD;
|
||
|
|
||
|
// `Array.prototype.lastIndexOf` method implementation
|
||
|
// https://tc39.es/ecma262/#sec-array.prototype.lastindexof
|
||
|
module.exports = FORCED ? function lastIndexOf(searchElement /* , fromIndex = @[*-1] */) {
|
||
|
// convert -0 to +0
|
||
|
if (NEGATIVE_ZERO) return $lastIndexOf.apply(this, arguments) || 0;
|
||
|
var O = toIndexedObject(this);
|
||
|
var length = toLength(O.length);
|
||
|
var index = length - 1;
|
||
|
if (arguments.length > 1) index = min(index, toInteger(arguments[1]));
|
||
|
if (index < 0) index = length + index;
|
||
|
for (;index >= 0; index--) if (index in O && O[index] === searchElement) return index || 0;
|
||
|
return -1;
|
||
|
} : $lastIndexOf;
|