Daily Logs/Algorithm Practice

[level 0] 문자 개수 세기

Jcob.moon 2025. 6. 14. 16:04

 

function solution(my_string) {
    const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    const answer = Array(52).fill(0);

    for (const char of my_string) {
        const index = alphabet.indexOf(char);
        answer[index]++;
    }

    return answer;
}