Example 1 — Lists and Strings (Official Samples)
Keep the last one, two, or more items — or the last characters of a string.
const names = ['foo', 'bar', 'baz'];
console.log(R.takeLast(1, names)); // ['baz']
console.log(R.takeLast(2, names)); // ['bar', 'baz']
console.log(R.takeLast(4, names)); // ['foo', 'bar', 'baz']
console.log(R.takeLast(3, 'ramda')); // 'mda' How It Works
- One.
R.takeLast(1, names)keeps only the last item, still inside an array. - Two.
R.takeLast(2, names)keeps the last two, in their original order. - Too many. Asking for 4 of 3 items returns all three — no error.
- String. For text, the last 3 characters come back as a string:
'mda'.
