Created
October 18, 2020 00:33
-
-
Save muhsalaa/6653754981b53c8e797e00d6501d2eb2 to your computer and use it in GitHub Desktop.
find first duplicate character in string
This file contains 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
function findDupe(str) { | |
let hash = {} | |
for (let x of str) { | |
hash[x] ? hash[x] += 1 : hash[x] = 1; | |
if (hash[x] === 2) return x | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment