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 |
|
7 |
|
8 | var createMethod = function (TYPE) {
|
9 | var IS_FIND_LAST_INDEX = TYPE === 1;
|
10 | return function ($this, callbackfn, that) {
|
11 | var O = toObject($this);
|
12 | var self = IndexedObject(O);
|
13 | var index = lengthOfArrayLike(self);
|
14 | var boundFunction = bind(callbackfn, that);
|
15 | var value, result;
|
16 | while (index-- > 0) {
|
17 | value = self[index];
|
18 | result = boundFunction(value, index, O);
|
19 | if (result) switch (TYPE) {
|
20 | case 0: return value;
|
21 | case 1: return index;
|
22 | }
|
23 | }
|
24 | return IS_FIND_LAST_INDEX ? -1 : undefined;
|
25 | };
|
26 | };
|
27 |
|
28 | module.exports = {
|
29 |
|
30 |
|
31 | findLast: createMethod(0),
|
32 |
|
33 |
|
34 | findLastIndex: createMethod(1)
|
35 | };
|