source: node_modules/ramda/es/takeLastWhile.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1.1 KB
Line 
1import _curry2 from "./internal/_curry2.js";
2import slice from "./slice.js";
3/**
4 * Returns a new list containing the last `n` elements of a given list, passing
5 * each value to the supplied predicate function, and terminating when the
6 * predicate function returns `false`. Excludes the element that caused the
7 * predicate function to fail. The predicate function is passed one argument:
8 * *(value)*.
9 *
10 * @func
11 * @memberOf R
12 * @since v0.16.0
13 * @category List
14 * @sig (a -> Boolean) -> [a] -> [a]
15 * @sig (a -> Boolean) -> String -> String
16 * @param {Function} fn The function called per iteration.
17 * @param {Array} xs The collection to iterate over.
18 * @return {Array} A new array.
19 * @see R.dropLastWhile, R.addIndex
20 * @example
21 *
22 * const isNotOne = x => x !== 1;
23 *
24 * R.takeLastWhile(isNotOne, [1, 2, 3, 4]); //=> [2, 3, 4]
25 *
26 * R.takeLastWhile(x => x !== 'R' , 'Ramda'); //=> 'amda'
27 */
28
29var takeLastWhile =
30/*#__PURE__*/
31_curry2(function takeLastWhile(fn, xs) {
32 var idx = xs.length - 1;
33
34 while (idx >= 0 && fn(xs[idx])) {
35 idx -= 1;
36 }
37
38 return slice(idx + 1, Infinity, xs);
39});
40
41export default takeLastWhile;
Note: See TracBrowser for help on using the repository browser.