코딩 테스트/프로그래머스 - 자바스크립트
프로그래머스 LV.0 특수문자 출력하기
ctrs
2023. 9. 7. 10:37
프로그래머스 LV.0 특수문자 출력하기
https://school.programmers.co.kr/learn/courses/30/lessons/181948
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
1. 문제 명
특수문자 출력하기
2. 문제 설명
다음과 같이 출력하도록 코드를 작성해 주세요.
3. 제한 사항
없음
4. 예시
!@#$%^&*(\'"<>?:; |
5. 기본 제공 코드
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.on('close', function () {
});
6. 제출한 내 답
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
rl.on("close", function () {
console.log(`!@#$%^&*(\\'"<>?:;`);
});
6-2. VSC에 작성한 내용
console.log(`!@#$%^&*(\\'"<>?:;`);
7. 특이사항
JavaScript에서 \(역슬래시)는 이스케이프 문자로 사용되기 때문에
문자열 내에서 \를 표시하려면 \\ 두번 입력하면 된다.
8. 다른 사람이 작성한 답
다들 역슬래시를 두번적는 방법으로 갔으나 특이한 케이스가 있었음
8-1. for of 문
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.on('close', function () {
s = "!@#$"+ "%^&*(\\'";
s += '"';
s += "<>?:;";
a = "";
for(let i of s){
a += i;
}
console.log(a)
});
굳이 이렇게까지 해야했을까? 싶은데
이 사람 나름대로의 고민이 담겨있는거겠지