[코딩테스트] JavaScript/[코테] 프로그래머스
[프로그래머스 / JS 코테] Lv.0 / 181945 : 문자열 돌리기
jini-dev
2025. 1. 6. 16:36
SMALL
문제 설명
문자열 str이 주어집니다.
문자열을 시계방향으로 90도 돌려서 아래 입출력 예와 같이 출력하는 코드를 작성해 보세요.
제한사항
- 1 ≤ str의 길이 ≤ 10
입출력 예
- 입력abcde
- 출력a b c d e
문제 풀이
for of 문을 사용하여 콘솔 한줄에 문자 하나씩 나타나도록 했다.
for of 문
반복 가능한 객체의 값을 반복한다.
문자열, 배열, Map, Set 등의 반복 가능한 데이터 구조에서 반복할 수 있다.
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
let input = [];
rl.on('line', function (line) {
input = [line]; // ['abcde']
}).on('close',function(){
str = input[0]; // 'abcde'
for (i of str){
console.log(i)
}
});
LIST