Skip to content

Instantly share code, notes, and snippets.

@emayom
Created August 22, 2021 07:03
Show Gist options
  • Save emayom/4a4b16fcfdfe247e02db5f04f5fba519 to your computer and use it in GitHub Desktop.
Save emayom/4a4b16fcfdfe247e02db5f04f5fba519 to your computer and use it in GitHub Desktop.
[프로그래머스] 최댓값과 최솟값
function solution(s) {
s = s.split(' ').sort((a,b) => a-b);
let answer = [(s[0]), s[s.length-1]];
return answer.join(' ');
}
function solution(s) {
s = s.split(' ');
const max = s.reduce((a,b) => { return Math.max(a,b) });
const min = s.reduce((a,b) => { return Math.min(a,b) });
return `${min} ${max}`;
}
function solution(s) {
s = s.split(' ');
const max = Math.max.apply(null, s);
const min = Math.min.apply(null, s);
return `${min} ${max}`;
}
// +) ES6 Spread Operator 사용 시 !
function solution(s) {
s = s.split(' ');
const max = Math.max(... s);
const min = Math.min(... s);
return `${min} ${max}`;
}
function solution(s) {
s = s.split(' ').map((el) => parseInt(el));
let max = s[0];
let min = s[0];
for(let i=1; i < s.length; i++){
(s[i] > max)? max = s[i] : (s[i] < min)? min = s[i] : '';
}
return `${min} ${max}`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment