How to Count the Number of Duplicate Characters in JavaScript?
I need to create a function that returns the number of duplicate characters in a string. It will be case sensitive and spaces are included. If there are no duplicates, return 0.
1 Answer
const duplicates = str => str.length - new Set(str).size;
Example
duplicates('1100') // 2
answer Link