Example 1 — Official Samples
Remove 1, 2, 3, and 4 items from the end of a list, then 3 characters from a string — straight from the Ramda docs.
const words = ['foo', 'bar', 'baz'];
console.log(R.dropLast(1, words)); // ['foo', 'bar']
console.log(R.dropLast(2, words)); // ['foo']
console.log(R.dropLast(3, words)); // []
console.log(R.dropLast(4, words)); // []
console.log(R.dropLast(3, 'ramda')); // 'ra' How It Works
- Remove from the end.
R.dropLast(1, words)removes'baz'and keeps the rest. - Bigger n. Removing 2 leaves only
'foo'; removing 3 empties the list. - Too many. Removing 4 from a 3-item list is not an error — you just get
[]. - Strings. A string returns a string: removing
'mda'leaves'ra'.
