(알고리즘) CodeWars : Descending Order

호두파파·2021년 4월 6일
0

알고리즘 연습

목록 보기
10/60
post-thumbnail

Description

Your task is to make a function that can take any non-negative integer as an argument and return it with its digits in descending order. Essentially, rearrange the digits to create the highest possible number.

Example

  • Input: 42145 Output: 54421
  • Input: 145263 Output: 654321
  • Input: 123456789 Output: 987654321

solutuon

function descendingOrder(n){
  return parseInt(String(n).split('').sort().reverse().join(''))
}
profile
안녕하세요 주니어 프론트엔드 개발자 양윤성입니다.

0개의 댓글