Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

js reverse int in descending order

//Method 1
//rearrange the digits to create the highest possible number
function descendingOrder(n){
  return parseInt(String(n).split('').sort().reverse().join(''));
}
console.log(descendingOrder(15));		// result:  51
console.log(descendingOrder(22314));	// result:  43221
 
PREVIOUS NEXT
Tagged: #js #reverse #int #descending #order
ADD COMMENT
Topic
Name
3+8 =