1 | var _curry2 =
|
2 | /*#__PURE__*/
|
3 | require("./internal/_curry2");
|
4 |
|
5 | var slice =
|
6 | /*#__PURE__*/
|
7 | require("./slice");
|
8 | /**
|
9 | * Returns a new list containing the last `n` elements of a given list, passing
|
10 | * each value to the supplied predicate function, and terminating when the
|
11 | * predicate function returns `false`. Excludes the element that caused the
|
12 | * predicate function to fail. The predicate function is passed one argument:
|
13 | * *(value)*.
|
14 | *
|
15 | * @func
|
16 | * @memberOf R
|
17 | * @since v0.16.0
|
18 | * @category List
|
19 | * @sig (a -> Boolean) -> [a] -> [a]
|
20 | * @sig (a -> Boolean) -> String -> String
|
21 | * @param {Function} fn The function called per iteration.
|
22 | * @param {Array} xs The collection to iterate over.
|
23 | * @return {Array} A new array.
|
24 | * @see R.dropLastWhile, R.addIndex
|
25 | * @example
|
26 | *
|
27 | * const isNotOne = x => x !== 1;
|
28 | *
|
29 | * R.takeLastWhile(isNotOne, [1, 2, 3, 4]); //=> [2, 3, 4]
|
30 | *
|
31 | * R.takeLastWhile(x => x !== 'R' , 'Ramda'); //=> 'amda'
|
32 | */
|
33 |
|
34 |
|
35 | var takeLastWhile =
|
36 | /*#__PURE__*/
|
37 | _curry2(function takeLastWhile(fn, xs) {
|
38 | var idx = xs.length - 1;
|
39 |
|
40 | while (idx >= 0 && fn(xs[idx])) {
|
41 | idx -= 1;
|
42 | }
|
43 |
|
44 | return slice(idx + 1, Infinity, xs);
|
45 | });
|
46 |
|
47 | module.exports = takeLastWhile; |
\ | No newline at end of file |