Created
August 22, 2021 07:03
-
-
Save emayom/4a4b16fcfdfe247e02db5f04f5fba519 to your computer and use it in GitHub Desktop.
[프로그래머스] 최댓값과 최솟값
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function solution(s) { | |
s = s.split(' ').sort((a,b) => a-b); | |
let answer = [(s[0]), s[s.length-1]]; | |
return answer.join(' '); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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