source: trip-planner-front/node_modules/core-js/internals/array-iteration-from-last.js

Last change on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.1 KB
Line 
1var bind = require('../internals/function-bind-context');
2var IndexedObject = require('../internals/indexed-object');
3var toObject = require('../internals/to-object');
4var toLength = require('../internals/to-length');
5
6// `Array.prototype.{ findLast, findLastIndex }` methods implementation
7var 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 boundFunction = bind(callbackfn, that, 3);
13 var index = toLength(self.length);
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
27module.exports = {
28 // `Array.prototype.findLast` method
29 // https://github.com/tc39/proposal-array-find-from-last
30 findLast: createMethod(0),
31 // `Array.prototype.findLastIndex` method
32 // https://github.com/tc39/proposal-array-find-from-last
33 findLastIndex: createMethod(1)
34};
Note: See TracBrowser for help on using the repository browser.