Created
September 6, 2021 15:55
-
-
Save QuatoHub/f5e70c9cde6b86defcf4f4bcb75afcc8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function countAllLetters(str) { | |
let obj = {}; // 변수에 빈 객체 할당 | |
for(let i = 0; i < str.length; i++){ // 반복문을 통해 인자로 받은 문자열 순회 | |
if (obj[str[i]] === undefined) { // i번째 문자가 기존 객체의 키로 존재하지 않으면 | |
obj[str[i]] = 0 // i번째 문자와 0을 새로운 키값으로 생성 | |
} | |
obj[str[i]]++ // 해당 문자가 반복될 때 마다 1씩 값을 추가한다. | |
} | |
return obj; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment