Count the number of Duplicates
Write a function that will return the count of distinct case-insensitive alphabetic characters and numeric digits that occur more than once in the input string. The input string can be assumed to contain only alphabets (both uppercase and lowercase) and numeric digits.
Вот задача
Вот моё решение:
function duplicateCount(text){
if(text.length!=0){
var count=0, j,myreg;
text=text.toLowerCase();
for(let i=0;i<text.length;i++){
myreg= new RegExp(text[i],'gi');
if(text.match(myreg).length>=2){
count++;
text = text.replace(myreg,'');
}
}
return count;
}else{
return 0;
}
}
Я понял задачу так: если встречаться символ более одного раза увеличиваем счётчик. В результате вывести счётчик.