Node-Red configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

array-last-index-of.js 1.3KB

12345678910111213141516171819202122232425262728
  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. var min = Math.min;
  9. var $lastIndexOf = [].lastIndexOf;
  10. var NEGATIVE_ZERO = !!$lastIndexOf && 1 / [1].lastIndexOf(1, -0) < 0;
  11. var STRICT_METHOD = arrayMethodIsStrict('lastIndexOf');
  12. var FORCED = NEGATIVE_ZERO || !STRICT_METHOD;
  13. // `Array.prototype.lastIndexOf` method implementation
  14. // https://tc39.es/ecma262/#sec-array.prototype.lastindexof
  15. module.exports = FORCED ? function lastIndexOf(searchElement /* , fromIndex = @[*-1] */) {
  16. // convert -0 to +0
  17. if (NEGATIVE_ZERO) return apply($lastIndexOf, this, arguments) || 0;
  18. var O = toIndexedObject(this);
  19. var length = lengthOfArrayLike(O);
  20. if (length === 0) return -1;
  21. var index = length - 1;
  22. if (arguments.length > 1) index = min(index, toIntegerOrInfinity(arguments[1]));
  23. if (index < 0) index = length + index;
  24. for (;index >= 0; index--) if (index in O && O[index] === searchElement) return index || 0;
  25. return -1;
  26. } : $lastIndexOf;