How to sort an array of integers?
The below program will sort an array of integers in ascending order.
const nos = 123496758789456;
console.log(nos);
const sorted = sorter(nos).join('')
console.log(sorted);
function sorter(nos){
const splitted = nos.toString().split('');
for(let i = 0; i < splitted.length; i++){
for(let j = i+1; j < splitted.length; j++){
if(parseInt(splitted[j-1]) > parseInt(splitted[j])){
let temp = splitted[j-1];
splitted.splice(j-1, 1);
splitted.splice(j, 0, temp);
}
}
}
return splitted;
}