프로그래머스 연습문제 - 최댓값과 최솟값(level2, JS)
function sol(s) {
s = s.split(' ');
s.sort((a, b) => parseInt(a) - parseInt(b));
return `${s[0]} ${s[s.length - 1]}`;
}
//또는
function solution(s) {
s = s.split(' ')
return `${Math.min(...s)} ${Math.max(...s)}`;
}
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Math/max
console.log(Math.max(1, 3, 2));
// Expected output: 3
console.log(Math.max(-1, -3, -2));
// Expected output: -1
const array1 = [1, 3, 2];
console.log(Math.max(...array1));
// Expected output: 3