Skip to content

Instantly share code, notes, and snippets.

@muhsalaa
Created October 18, 2020 00:33
Show Gist options
  • Save muhsalaa/6653754981b53c8e797e00d6501d2eb2 to your computer and use it in GitHub Desktop.
Save muhsalaa/6653754981b53c8e797e00d6501d2eb2 to your computer and use it in GitHub Desktop.
find first duplicate character in string
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