main
Last change
on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 2 weeks ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
1.3 KB
|
Rev | Line | |
---|
[79a0317] | 1 | 'use strict';
|
---|
| 2 | /* eslint-disable es/no-array-prototype-lastindexof -- safe */
|
---|
| 3 | var apply = require('../internals/function-apply');
|
---|
| 4 | var toIndexedObject = require('../internals/to-indexed-object');
|
---|
| 5 | var toIntegerOrInfinity = require('../internals/to-integer-or-infinity');
|
---|
| 6 | var lengthOfArrayLike = require('../internals/length-of-array-like');
|
---|
| 7 | var arrayMethodIsStrict = require('../internals/array-method-is-strict');
|
---|
| 8 |
|
---|
| 9 | var min = Math.min;
|
---|
| 10 | var $lastIndexOf = [].lastIndexOf;
|
---|
| 11 | var NEGATIVE_ZERO = !!$lastIndexOf && 1 / [1].lastIndexOf(1, -0) < 0;
|
---|
| 12 | var STRICT_METHOD = arrayMethodIsStrict('lastIndexOf');
|
---|
| 13 | var FORCED = NEGATIVE_ZERO || !STRICT_METHOD;
|
---|
| 14 |
|
---|
| 15 | // `Array.prototype.lastIndexOf` method implementation
|
---|
| 16 | // https://tc39.es/ecma262/#sec-array.prototype.lastindexof
|
---|
| 17 | module.exports = FORCED ? function lastIndexOf(searchElement /* , fromIndex = @[*-1] */) {
|
---|
| 18 | // convert -0 to +0
|
---|
| 19 | if (NEGATIVE_ZERO) return apply($lastIndexOf, this, arguments) || 0;
|
---|
| 20 | var O = toIndexedObject(this);
|
---|
| 21 | var length = lengthOfArrayLike(O);
|
---|
| 22 | if (length === 0) return -1;
|
---|
| 23 | var index = length - 1;
|
---|
| 24 | if (arguments.length > 1) index = min(index, toIntegerOrInfinity(arguments[1]));
|
---|
| 25 | if (index < 0) index = length + index;
|
---|
| 26 | for (;index >= 0; index--) if (index in O && O[index] === searchElement) return index || 0;
|
---|
| 27 | return -1;
|
---|
| 28 | } : $lastIndexOf;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.