2 var toIndexedObject = require('../internals/to-indexed-object');
3 var toInteger = require('../internals/to-integer');
4 var toLength = require('../internals/to-length');
5 var arrayMethodIsStrict = require('../internals/array-method-is-strict');
6 var arrayMethodUsesToLength = require('../internals/array-method-uses-to-length');
9 var nativeLastIndexOf = [].lastIndexOf;
10 var NEGATIVE_ZERO = !!nativeLastIndexOf && 1 / [1].lastIndexOf(1, -0) < 0;
11 var STRICT_METHOD = arrayMethodIsStrict('lastIndexOf');
12 // For preventing possible almost infinite loop in non-standard implementations, test the forward version of the method
13 var USES_TO_LENGTH = arrayMethodUsesToLength('indexOf', { ACCESSORS: true, 1: 0 });
14 var FORCED = NEGATIVE_ZERO || !STRICT_METHOD || !USES_TO_LENGTH;
16 // `Array.prototype.lastIndexOf` method implementation
17 // https://tc39.github.io/ecma262/#sec-array.prototype.lastindexof
18 module.exports = FORCED ? function lastIndexOf(searchElement /* , fromIndex = @[*-1] */) {
20 if (NEGATIVE_ZERO) return nativeLastIndexOf.apply(this, arguments) || 0;
21 var O = toIndexedObject(this);
22 var length = toLength(O.length);
23 var index = length - 1;
24 if (arguments.length > 1) index = min(index, toInteger(arguments[1]));
25 if (index < 0) index = length + index;
26 for (;index >= 0; index--) if (index in O && O[index] === searchElement) return index || 0;
28 } : nativeLastIndexOf;