const fs = require('fs');
const path = process.platform === 'linux' ? '/dev/stdin' : './input.txt';
const input = fs.readFileSync(path).toString().split('\n');
function solve(input) {
const count = Number(input[0]);
const array = input[1].split(' ').map((value) => Number(value));
console.log(`${Math.min(...array)} ${Math.max(...array)}`);
// array.sort((a, b) => a - b);
// let min = array[0];
// let max = array[count - 1];
// console.log(`${min} ${max}`);
}
solve(input);
์๋ฐ์คํฌ๋ฆฝํธ ๋ฐฐ์ด์ spread์ ์์คํจ์ ๋ค์ ๋๋ผ๊ฒ ํด์ค ๋ฌธ์ !
๋จ์ํ๊ฒ ์๊ฐํ๋ฉด Math.max(array)๋ฅผ ํ๋ฉด ์ต๋๊ฐ์ด ๋์ฌ ๊ฒ ๊ฐ์ง๋ง, Math.max๋ ํน์ valueํํ์ ๊ฐ์ ๋ฐ๊ธฐ ๋๋ฌธ์
undefined๊ฐ ๋ฐํ๋๋ค. ์ฆ, Math.max(...array)ํํ๋ฅผ ์ทจํด์ฃผ์ด์ผ ์ต๋๊ฐ์ ๊ตฌํ ์ ์๋ค. :)
'๐ JavaScript > ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[JS] 1065 (0) | 2022.05.15 |
---|---|
[JS] 4673 (0) | 2022.05.15 |
[JS] 3052 (0) | 2022.05.14 |
[JS] 8958 (0) | 2022.05.14 |
[JS] 4344 (0) | 2022.05.14 |