Example 1 — Official: Same Text Counts as Duplicate
Treat 1 and '1' as the same value and keep whichever comes first.
const strEq = R.eqBy(String);
console.log(R.uniqWith(strEq)([1, '1', 2, 1])); // [1, 2]
console.log(R.uniqWith(strEq)(['1', 1, 1])); // ['1'] How It Works
- The test.
R.eqBy(String)builds(a, b) => String(a) === String(b). - First list.
1is kept;'1'and the last1both match it and are dropped;2is new. - Second list.
'1'comes first now, so the string is kept and both numbers are dropped. - Lesson. The test decides what matches; list order decides which item survives.
