Example 1 — Official Samples
Keep items from the end until you hit 1, then do the same on a string.
const isNotOne = x => x !== 1;
console.log(R.takeLastWhile(isNotOne, [1, 2, 3, 4])); // [2, 3, 4]
console.log(R.takeLastWhile(x => x !== 'R', 'Ramda')); // 'amda' How It Works
- Start at the end.
4,3, and2are not1, so they are kept. - Stop.
1fails the test, so the walk ends there and1is excluded. - Original order. The kept items come back as
[2, 3, 4], not reversed. - Strings. Each character is tested; everything after
'R'is kept, and the result is the string'amda'.
