DEV Community

Discussion on: Find Duplicates in an Array

Collapse
 
ustice profile image
Jason Kleinberg

Here's another version of findMapForReduce as a one-liner that's still very readable:

const findMapForReduce = (data) => data.reduce(
  ([ seen, repeated ], element) => seen.has(element)
      ? [ seen, repeated.set(element, true) ]
      : [ seen.set(element, true), repeated ], 
  [ new Map(), new Map() ]
)[1].keys()