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-iteration-from-last.js 1.2KB

1234567891011121314151617181920212223242526272829303132333435
  1. 'use strict';
  2. var bind = require('../internals/function-bind-context');
  3. var IndexedObject = require('../internals/indexed-object');
  4. var toObject = require('../internals/to-object');
  5. var lengthOfArrayLike = require('../internals/length-of-array-like');
  6. // `Array.prototype.{ findLast, findLastIndex }` methods implementation
  7. var createMethod = function (TYPE) {
  8. var IS_FIND_LAST_INDEX = TYPE === 1;
  9. return function ($this, callbackfn, that) {
  10. var O = toObject($this);
  11. var self = IndexedObject(O);
  12. var index = lengthOfArrayLike(self);
  13. var boundFunction = bind(callbackfn, that);
  14. var value, result;
  15. while (index-- > 0) {
  16. value = self[index];
  17. result = boundFunction(value, index, O);
  18. if (result) switch (TYPE) {
  19. case 0: return value; // findLast
  20. case 1: return index; // findLastIndex
  21. }
  22. }
  23. return IS_FIND_LAST_INDEX ? -1 : undefined;
  24. };
  25. };
  26. module.exports = {
  27. // `Array.prototype.findLast` method
  28. // https://github.com/tc39/proposal-array-find-from-last
  29. findLast: createMethod(0),
  30. // `Array.prototype.findLastIndex` method
  31. // https://github.com/tc39/proposal-array-find-from-last
  32. findLastIndex: createMethod(1)
  33. };