Created
August 5, 2018 20:55
-
-
Save akhilome/56e0d4e4a8f2c45a195a493a3133c13f to your computer and use it in GitHub Desktop.
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 duplicateCount(text) { | |
if (!text) return 0; // no need moving forward if input is empty | |
const tracker = new Set(); // keep track of all characters in the input | |
const dupes = new Set(); // keep track of duplicate characters | |
for (const char of text.toLowerCase()) { | |
if(tracker.has(char)) { | |
dupes.add(char); | |
} else { | |
tracker.add(char); | |
} | |
} | |
return dupes.size; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment