Answers for "js reverse int in descending order"

0

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
Posted by: Guest on April-01-2021
0

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
Posted by: Guest on April-01-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language