Skip to content

Instantly share code, notes, and snippets.

@phunguyen19
Created May 20, 2019 10:46
Show Gist options
  • Select an option

  • Save phunguyen19/96a6b16ed4f842e8bfdafb7586449035 to your computer and use it in GitHub Desktop.

Select an option

Save phunguyen19/96a6b16ed4f842e8bfdafb7586449035 to your computer and use it in GitHub Desktop.
js check if array is duplicate
// Using ES 6, shortest and most readable solution
(new Set(myArray)).size !== myArray.length
// Using Array.some, this is fastest solution
myArray.some((value, index, array) => array.includes(value, index + 1))
// Using filter
passphrases.filter(function (value, index, self) { return self.indexOf(value) === index; }).length !== passphrases.length
// Source for benchmark: https://jsbench.me/mqjvw8exl9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment