| Viewed 156 times

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
Mohammad Qandeel
const duplicates = str => str.length - new Set(str).size;


duplicates('1100') // 2

Related Questions