How to sort the digits of a number in ascending order with Node.js

1 Answer

0 votes
let n = 84931;
let s = n.toString();
 
let arr = s.split('');
arr.sort();
s = arr.join('');
 
n = parseInt(s, 10);
  
console.log(n);
 
  
  
/*
run:
  
13489
  
*/

 



answered Aug 13, 2024 by avibootz

Related questions

2 answers 151 views
1 answer 160 views
1 answer 117 views
...