PageRenderTime 22ms CodeModel.GetById 14ms app.highlight 3ms RepoModel.GetById 2ms app.codeStats 0ms

/node_modules/lodash/takeRightWhile.js

https://bitbucket.org/coleman333/smartsite
JavaScript | 45 lines | 8 code | 2 blank | 35 comment | 1 complexity | f0099b7e59bd9e7a45268f90dff7f291 MD5 | raw file
 1var baseIteratee = require('./_baseIteratee'),
 2    baseWhile = require('./_baseWhile');
 3
 4/**
 5 * Creates a slice of `array` with elements taken from the end. Elements are
 6 * taken until `predicate` returns falsey. The predicate is invoked with
 7 * three arguments: (value, index, array).
 8 *
 9 * @static
10 * @memberOf _
11 * @since 3.0.0
12 * @category Array
13 * @param {Array} array The array to query.
14 * @param {Function} [predicate=_.identity] The function invoked per iteration.
15 * @returns {Array} Returns the slice of `array`.
16 * @example
17 *
18 * var users = [
19 *   { 'user': 'barney',  'active': true },
20 *   { 'user': 'fred',    'active': false },
21 *   { 'user': 'pebbles', 'active': false }
22 * ];
23 *
24 * _.takeRightWhile(users, function(o) { return !o.active; });
25 * // => objects for ['fred', 'pebbles']
26 *
27 * // The `_.matches` iteratee shorthand.
28 * _.takeRightWhile(users, { 'user': 'pebbles', 'active': false });
29 * // => objects for ['pebbles']
30 *
31 * // The `_.matchesProperty` iteratee shorthand.
32 * _.takeRightWhile(users, ['active', false]);
33 * // => objects for ['fred', 'pebbles']
34 *
35 * // The `_.property` iteratee shorthand.
36 * _.takeRightWhile(users, 'active');
37 * // => []
38 */
39function takeRightWhile(array, predicate) {
40  return (array && array.length)
41    ? baseWhile(array, baseIteratee(predicate, 3), false, true)
42    : [];
43}
44
45module.exports = takeRightWhile;