taesik

Count the number of occurrences of each character and return it as a list of tuples in order 본문

functions and trick/typescript_javascript

Count the number of occurrences of each character and return it as a list of tuples in order

taesikk 2022. 1. 23. 14:11
orderedCount("abbbbbcccc") == [['a', 1], ['b', 5], ['c', 4]];

 

 

solution  

 

더보기
export function orderedCount(text: string): [string, number][] {
   return [...new Set(text)].map((x: string) => [x, text.split(x).length - 1])
}