Example 1 — Official: Unique by Absolute Value
Treat numbers the same distance from zero as duplicates.
console.log(R.uniqBy(Math.abs, [-1, -5, 2, 10, 1, 2])); // [-1, -5, 2, 10] How It Works
- Keys.
Math.absturns the list into keys1, 5, 2, 10, 1, 2. - New keys. The first four keys are new, so
-1,-5,2and10are kept. - Repeated keys.
1and the second2produce keys already seen, so they are dropped. - Originals. The result holds
-1and-5, not their keys1and5.
