[d24f17c] | 1 | import _curry2 from "./internal/_curry2.js";
|
---|
| 2 | import 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 |
|
---|
| 29 | var 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 |
|
---|
| 41 | export default takeLastWhile; |
---|