Q:

Write a JavaScript program to filter out the non-unique values in an array, based on a provided comparator function

0

 Write a JavaScript program to filter out the non-unique values in an array, based on a provided comparator function.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

const filter_Non_UniqueBy = (arr, fn) =>
  arr.filter((v, i) => arr.every((x, j) => (i === j) === fn(v, x, i, j)));

console.log(filter_Non_UniqueBy(
  [
    { id: 0, value: 'a' },
    { id: 1, value: 'b' },
    { id: 2, value: 'c' },
    { id: 1, value: 'd' },
    { id: 0, value: 'e' }
  ],
  (a, b) => a.id == b.id
)); 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now