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)ํ˜•ํƒœ๋ฅผ ์ทจํ•ด์ฃผ์–ด์•ผ ์ตœ๋Œ“๊ฐ’์„ ๊ตฌํ•  ์ˆ˜ ์žˆ๋‹ค. :)