Created
February 11, 2021 21:03
-
-
Save elersong/ea98a3bd76b080542fa5ef3516c5a181 to your computer and use it in GitHub Desktop.
Check for duplicate array values
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
// test if string contains any duplicate chars | |
function isUniq(str) { | |
let letters = {}; | |
str.split('').forEach(char => { | |
if (letters[char]) { | |
letters[char] = false; | |
} else { | |
letters[char] = true; | |
} | |
}); | |
// If the letters object has any false values, there's one or more duplicates | |
return !Object.values(letters).includes(false); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment