리펙토링 전
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
let input = [];
rl.on('line', function (x) {
input.push(x);
if (input.length >= 3) {
rl.close();
}
}).on('close', function () {
letcardssplit = input[1].split(' ');
answer = 0;
letcardssplit.map(v => {
if (v === input[2]) {
answer++;
}
});
console.log(answer);
process.exit();
});
바꾼거
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
let input = [];
rl.on('line', function (x) {
input.push(x);
if (input.length >= 3) {
rl.close();
}
}).on('close', function () {
const [first, second, third] = input;
const secondArr = second.split(' ');
let count = secondArr.filter(el => el == third).length;
console.log(count);
process.exit();
});
알게된것 1.구조분해할당
const [first, second, third] = input;
알게된것 2. filter쓰는 방법
let count = secondArr.filter(el => el == third).length;
'Javascript' 카테고리의 다른 글
Javascript reduce사용법 (0) | 2022.10.02 |
---|---|
객체안에 함수에서 변수를 접근할 경우 this를 붙여야한다 (0) | 2022.10.01 |
타입변환, {}의중의적표현,this (0) | 2022.09.28 |
자바스크립트에서 비동기 처리가 가능하게 해주는 Web API (0) | 2022.09.21 |
원시타입, 객체타입 변수와 깊은복사, 얕은복사 (0) | 2022.09.07 |