SMALL
1. 덧셈식 출력하기
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
let input = [];
rl.on('line', function (line) {
input = line.split(' ');
}).on('close', function () {
console.log(`${Number(input[0])} + ${Number(input[1])} = ${Number(input[0]) + Number(input[1])}`);
});
2. 문자열 붙여서 출력하기
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
let input = [];
rl.on('line', function (line) {
input = line.split(' ');
}).on('close', function () {
str1 = input[0];
str2 = input[1];
console.log(str1.concat(str2)); // concat을 이용하여 str1과 str2 연결
});
3. 문자열 돌리기
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
let input = [];
rl.on('line', function (line) {
input = [line];
}).on('close',function(){
str = input[0];
[...str].forEach(a => {
console.log(a);
})
// forEach 반복문 사용.
// ** 그 주체는 str 모든 것!
});
4. 홀짝 구분하기
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
let input = [];
rl.on('line', function (line) {
input = line.split(' ');
}).on('close', function () {
n = Number(input[0]);
result = (n%2==0) ? (n + " is even") : (n + " is odd"); // 삼항연산자 사용
console.log(result);
});
5. 문자열 겹쳐쓰기
function solution(my_string, overwrite_string, s) {
var answer = [...my_string]; // ** 단어 하나하나 별로 다 분할됨.
answer.splice(s, overwrite_string.length, overwrite_string);
// ** s번째에서 겹치는 부분의 길이를 삭제하고, 그 부분을 겹쳐쓰는 문자열로 대신함.
return answer.join(""); // ** 단어 합치기
}
728x90
'Algorithm > Javascript' 카테고리의 다른 글
[프로그래머스] 230707 코딩테스트 연습 (0) | 2023.07.08 |
---|---|
[프로그래머스] 230706 코딩테스트 연습 (0) | 2023.07.06 |
[프로그래머스] 230705 코딩테스트 연습 (0) | 2023.07.05 |
[프로그래머스] 230704 코딩테스트 연습 (0) | 2023.07.04 |
[프로그래머스] 230630 코딩테스트 연습 (0) | 2023.07.01 |
댓글