Created
May 20, 2019 10:46
-
-
Save phunguyen19/96a6b16ed4f842e8bfdafb7586449035 to your computer and use it in GitHub Desktop.
js check if array is duplicate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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