showing results for - "js reverse int in descending order"
Greta
14 Aug 2018
1//Method 1
2//rearrange the digits to create the highest possible number
3function descendingOrder(n){
4  return parseInt(String(n).split('').sort().reverse().join(''));
5}
6console.log(descendingOrder(15));		// result:  51
7console.log(descendingOrder(22314));	// result:  43221
Anna
04 Aug 2017
1//Method 2
2//rearrange the digits to create the highest possible number
3function descendingOrder(n){
4  let reversed = n.toString().split("").sort((a, b) => b - a).join('');
5  return parseInt(reversed) * Math.sign(n);
6}
7console.log(descendingOrder(463));		// result:  643
8console.log(descendingOrder(223744));	// result:  744322