js-mentorship-razvan / javascript

Javascript study notes
GNU General Public License v3.0
22 stars 2 forks source link

Counting Duplicates #548

Closed RazvanBugoi closed 4 years ago

RazvanBugoi commented 4 years ago

https://www.codewars.com/kata/54bf1c2cd5b56cc47f0007a1/train/javascript

RazvanBugoi commented 4 years ago
function duplicateCount(text){
  text = text.toLowerCase();
  let obj ={};
  for (let i=0; i<text.length; i++) {
    if(text[i] in obj) {
    obj[text[i]] += 1;
} else {
    obj[text[i]] = 1;
}
}
  return Object.values(obj).filter((el) => el > 1).length;
}