1 | 'use strict';
|
2 | var toIndexedObject = require('../internals/to-indexed-object');
|
3 | var toInteger = require('../internals/to-integer');
|
4 | var toLength = require('../internals/to-length');
|
5 | var sloppyArrayMethod = require('../internals/sloppy-array-method');
|
6 |
|
7 | var min = Math.min;
|
8 | var nativeLastIndexOf = [].lastIndexOf;
|
9 | var NEGATIVE_ZERO = !!nativeLastIndexOf && 1 / [1].lastIndexOf(1, -0) < 0;
|
10 | var SLOPPY_METHOD = sloppyArrayMethod('lastIndexOf');
|
11 |
|
12 |
|
13 |
|
14 | module.exports = (NEGATIVE_ZERO || SLOPPY_METHOD) ? function lastIndexOf(searchElement /* , fromIndex = @[*-1] */) {
|
15 |
|
16 | if (NEGATIVE_ZERO) return nativeLastIndexOf.apply(this, arguments) || 0;
|
17 | var O = toIndexedObject(this);
|
18 | var length = toLength(O.length);
|
19 | var index = length - 1;
|
20 | if (arguments.length > 1) index = min(index, toInteger(arguments[1]));
|
21 | if (index < 0) index = length + index;
|
22 | for (;index >= 0; index--) if (index in O && O[index] === searchElement) return index || 0;
|
23 | return -1;
|
24 | } : nativeLastIndexOf;
|