Example 1 — Split on Every 2 (Official Sample)
Every 2 is a separator: it cuts the list and disappears.
const list = [1, 2, 3, 2, 4, 5, 2, 6, 7];
console.log(R.splitWhenever(R.equals(2), list)); // [[1], [3], [4, 5], [6, 7]]
console.log(list); // [1, 2, 3, 2, 4, 5, 2, 6, 7] How It Works
- The test.
R.equals(2)marks every2as a separator. - Collect. Items that are not
2go into the current chunk. - Cut and drop. Each
2closes the current chunk and is not kept anywhere. - Nothing changed. Four new chunks come back;
liststill has all its2s.
