Files
30-seconds-of-code/test/uniqueElementsBy/uniqueElementsBy.js
Angelos Chalaris b129b46c0d Tags and tests
2018-07-18 21:02:42 +03:00

6 lines
160 B
JavaScript

const uniqueElementsBy = (arr, fn) =>
arr.reduce((acc, v) => {
if (!acc.some(x => fn(v, x))) acc.push(v);
return acc;
}, []);
module.exports = uniqueElementsBy;