const fs = require('fs');
const path = process.platform === 'linux' ? '/dev/stdin' : './input.txt';
const input = fs
.readFileSync(path)
.toString()
.trim()
.split('\n')
.map((x) => Number(x));
const inputDiv = input.map((x) => x % 42);
const answer = new Set(inputDiv);
console.log([...answer].length);
trim() ์ ๋ฌด์ ๋ฐ๋ผ ์ ๋ต์ด ๋๊ธฐ๋ ์๋๊ธฐ๋ => ์ด์ ๋ฅผ ๋ชจ๋ฅด๊ณ๋ค. ์๋ค ๊ณต๋ฐฑ ์ ๊ฑฐํด์ฃผ๋ ์ํด์ฃผ๋ ์ด์ฐจํผ ์ซ์ํ์ผ๋ก ๋ฐ๋๋๋ฐ..
ํด๊ฒฐ : trim()์ ์ํ๊ณ ๋ฐฐ์ด์ ๋ฐ๊ฒ ๋๋ฉด ๋ง์ง๋ง ๊ฐ์ผ๋ก ''๊ฐ ๋ฐ์์ง๊ณ ์ด ๊ฐ์ Number๋ฅผ ์ด์ฉํด ์ซ์๋ก ๋ฐ๊พธ๋ฉด 0์ด ๋๋ค.
๋ฐ๋ผ์ trim()์ ์ต๊ด์ ์ผ๋ก ํด์ฃผ์!
'๐ JavaScript > ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[JS] 4673 (0) | 2022.05.15 |
---|---|
[JS] 10818 (0) | 2022.05.14 |
[JS] 8958 (0) | 2022.05.14 |
[JS] 4344 (0) | 2022.05.14 |
[JS] 1110 (0) | 2022.05.12 |