Example 1 — Official: Remove Odd Numbers
The array sample from the Ramda docs: drop every odd number.
const isOdd = (n) => n % 2 === 1;
console.log(R.reject(isOdd, [1, 2, 3, 4]));
// [2, 4] How It Works
- Test.
isOddreturnstruewhen a number leaves remainder 1 after dividing by 2. - Drop.
1and3pass the test, soR.rejectleaves them out. - Keep.
2and4fail the test, so they are copied into a new array. - No mutation. The original array still holds
[1, 2, 3, 4].
