Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

js reverse int in descending order

//Method 2
//rearrange the digits to create the highest possible number
function descendingOrder(n){
  let reversed = n.toString().split("").sort((a, b) => b - a).join('');
  return parseInt(reversed) * Math.sign(n);
}
console.log(descendingOrder(463));		// result:  643
console.log(descendingOrder(223744));	// result:  744322
 
PREVIOUS NEXT
Tagged: #js #reverse #int #descending #order
ADD COMMENT
Topic
Name
5+9 =