codewars: Highest and Lowest

Jieun·2021년 1월 9일
0

js알고리즘

목록 보기
3/6

✅ 문제

In this little assignment you are given a string of space separated numbers, and have to return the highest and lowest number.

  • All numbers are valid Int32, no need to validate them.
  • There will always be at least one number in the input string.
  • Output string must be two numbers separated by a single space, and highest number is first.

해석 : 띄어쓰기 되어있는 숫자들의 스트링에서 가장 큰 수와 작은 수를 리턴하라. 모든 수는 정수이며, 최소 하나의 숫자가 있고, 아웃풋 스트링은 '큰 수+띄어쓰기+작은 수'여야 한다.


✅ 예시

highAndLow("1 2 3 4 5");  // return "5 1"
highAndLow("1 2 -3 4 5"); // return "5 -3"
highAndLow("1 9 3 4 -5"); // return "9 -5"



✅ 내가 만든 답

function highAndLow(numbers){
    return `${Math.max(...numbers.split(' '))} ${Math.min(...numbers.split(' '))}`
  }
  • 이전 코테를 참고해 한 줄 짜리 코드를 만들었다.


0개의 댓글

Powered by GraphCDN, the GraphQL CDN