Skip to content

Instantly share code, notes, and snippets.

@renie
Created October 31, 2018 17:15
Show Gist options
  • Save renie/773dd2401f61f0ebffbf573aae8d80a1 to your computer and use it in GitHub Desktop.
Save renie/773dd2401f61f0ebffbf573aae8d80a1 to your computer and use it in GitHub Desktop.
const sameAsNextIndex = (item, index, array) => item === array[index + 1]
const sameAsPrevIndex = (item, index, array) => item === array[index - 1]
const isDuplicatedOnSortedMapper =
(item, index, array) =>
sameAsNextIndex(item, index, array)
? item
: sameAsPrevIndex(item, index, array)
? item
: null
const getDuplicated =
list =>
[...list]
.sort()
.map(isDuplicatedOnSortedMapper)
.filter(item => item)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment