Skip to content

Instantly share code, notes, and snippets.

@akhilome
Created August 5, 2018 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akhilome/56e0d4e4a8f2c45a195a493a3133c13f to your computer and use it in GitHub Desktop.
Save akhilome/56e0d4e4a8f2c45a195a493a3133c13f to your computer and use it in GitHub Desktop.
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