Skip to content

Latest commit

 

History

History
33 lines (24 loc) · 730 Bytes

descending-order.md

File metadata and controls

33 lines (24 loc) · 730 Bytes

Descending Order 7 Kyu

LINK TO THE KATA - FUNDAMENTALS

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.

Examples:

Input: 42145 Output: 54421

Input: 145263 Output: 654321

Input: 123456789 Output: 987654321

Solution

const descendingOrder = n => {
  return Number(
    n
      .toString()
      .split('')
      .sort((a, b) => b - a)
      .join(''),
  )
}