source: imaps-frontend/node_modules/lodash-es/findLastIndex.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.7 KB
RevLine 
[d565449]1import baseFindIndex from './_baseFindIndex.js';
2import baseIteratee from './_baseIteratee.js';
3import toInteger from './toInteger.js';
4
5/* Built-in method references for those with the same name as other `lodash` methods. */
6var nativeMax = Math.max,
7 nativeMin = Math.min;
8
9/**
10 * This method is like `_.findIndex` except that it iterates over elements
11 * of `collection` from right to left.
12 *
13 * @static
14 * @memberOf _
15 * @since 2.0.0
16 * @category Array
17 * @param {Array} array The array to inspect.
18 * @param {Function} [predicate=_.identity] The function invoked per iteration.
19 * @param {number} [fromIndex=array.length-1] The index to search from.
20 * @returns {number} Returns the index of the found element, else `-1`.
21 * @example
22 *
23 * var users = [
24 * { 'user': 'barney', 'active': true },
25 * { 'user': 'fred', 'active': false },
26 * { 'user': 'pebbles', 'active': false }
27 * ];
28 *
29 * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
30 * // => 2
31 *
32 * // The `_.matches` iteratee shorthand.
33 * _.findLastIndex(users, { 'user': 'barney', 'active': true });
34 * // => 0
35 *
36 * // The `_.matchesProperty` iteratee shorthand.
37 * _.findLastIndex(users, ['active', false]);
38 * // => 2
39 *
40 * // The `_.property` iteratee shorthand.
41 * _.findLastIndex(users, 'active');
42 * // => 0
43 */
44function findLastIndex(array, predicate, fromIndex) {
45 var length = array == null ? 0 : array.length;
46 if (!length) {
47 return -1;
48 }
49 var index = length - 1;
50 if (fromIndex !== undefined) {
51 index = toInteger(fromIndex);
52 index = fromIndex < 0
53 ? nativeMax(length + index, 0)
54 : nativeMin(index, length - 1);
55 }
56 return baseFindIndex(array, baseIteratee(predicate, 3), index, true);
57}
58
59export default findLastIndex;
Note: See TracBrowser for help on using the repository browser.