🔬Computer Science/코딩테스트

백준 10809 알파벳 찾기 // 자바스크립트로 a부터 z까지 출력하기

hellohailie 2022. 6. 28. 23:00

 

자바스크립트로 a부터 z까지 출력하기

let str = '';	

for (let i = 97; i <= 122; i++) {
    console.log(String.fromCharCode(i));
    
    str += String.fromCharCode(i);
}

// abcdefghijklmnopqrstuvwxyz
console.log(str);

 

😅 위와 같이 String.fromCharCode() 라는 메서드가 있는 줄 모르고 아래처럼 하드 코딩을 해서 문제를 풀려고 했는데 너무나 비효율적인 방법이라 구글링해서 위와 같은 식을 발견했습니다. 

 

const alphabet = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"];

👍

 

 

 

참고)

https://www.acmicpc.net/problem/10809

https://gurtn.tistory.com/76

https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode

 

😃 잘못된 개념 전달이 있다면 댓글 부탁드립니다. 저의 성장에 큰 도움이 됩니다🤓