Example 1 — Split a List (Official Sample)
Cut [1, 2, 3] after the first item.
const nums = [1, 2, 3];
console.log(R.splitAt(1, nums)); // [[1], [2, 3]]
console.log(nums); // [1, 2, 3] How It Works
- Number the items.
1is index 0,2is index 1,3is index 2. - Cut before index 1. Everything before it,
[1], becomes part 1. - The rest is part 2. The item at index 1 and everything after:
[2, 3]. - A new pair. Both parts are new arrays;
numsis unchanged.
