๐ JavaScript/๋ฐฑ์ค
[JS] 10818
Jayden1116
2022. 5. 14. 00:54
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)ํํ๋ฅผ ์ทจํด์ฃผ์ด์ผ ์ต๋๊ฐ์ ๊ตฌํ ์ ์๋ค. :)