1 var bind = require('../internals/function-bind-context');
2 var IndexedObject = require('../internals/indexed-object');
3 var toObject = require('../internals/to-object');
4 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 boundFunction = bind(callbackfn, that);
13 var index = lengthOfArrayLike(self);
17 result = boundFunction(value, index, O);
18 if (result) switch (TYPE) {
19 case 0: return value; // findLast
20 case 1: return index; // findLastIndex
23 return IS_FIND_LAST_INDEX ? -1 : undefined;
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)