Example 1 — Start and End Index (Official Sample)
Keep a middle window, then keep everything from index 1 with Infinity.
const letters = ['a', 'b', 'c', 'd'];
console.log(R.slice(1, 3, letters)); // ['b', 'c']
console.log(R.slice(1, Infinity, letters)); // ['b', 'c', 'd']
console.log(letters); // ['a', 'b', 'c', 'd'] How It Works
- Number the items.
ais index 0,bis 1,cis 2,dis 3. - Start is kept.
R.slice(1, 3)begins at index 1 ('b'). - End is not kept. It stops before index 3, so the result is
['b', 'c']— two items, because 3 − 1 = 2. - To the end.
Infinityas the end means “keep going until the list runs out”. - No mutation.
lettersstill has all four items.
