[Algorithm] 29 week(8.01 ~ 8.07) 2/3

Dev_min·2022년 8월 2일
0

algorithm

목록 보기
91/157

1941. Check if All Characters Have Equal Number of Occurrences

var areOccurrencesEqual = function(s) {
    let result = true;
    const sortedString = s.split('').sort((a, b) => a - b);
    const strings = {}
    
    for(let i = 0; i < sortedString.length; i++){
        if(!strings[sortedString[i]]){
            strings[sortedString[i]] = 1;
        }else{
            strings[sortedString[i]] += 1;
        }
    }
    
    const stringValues = Object.values(strings);

    return stringValues.every((value) => value === stringValues[0]);
};
profile
TIL record

0개의 댓글