← Back to challenges

Count the Number of Duplicate Characters

JavaScriptHardstringsvalidationinterview

Instructions

Create a function that takes a string and returns the number of alphanumeric characters that occur more than once.

Examples

duplicateCount("abcde") ➞ 0

duplicateCount("aabbcde") ➞ 2

duplicateCount("Indivisibilities") ➞ 2

duplicateCount("Aa") ➞ 0
// Case sensitive

Notes

  • Duplicate characters are case sensitive.
  • The input string will contain only alphanumeric characters.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Function to Arrow Function