taesik

Counting Duplicates 본문

functions and trick/typescript_javascript

Counting Duplicates

taesikk 2022. 1. 29. 18:23

 

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.

export function duplicateCount(text: string): number{
  let array = text.toLowerCase().split('');
  return [...new Set(array.filter((e,i) => array.indexOf(e) !== i))].length;
}