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