I am trying to sort a string which contains a single number from 1-9. For e.g. string is "Ho2w are1 y3ou" then resulting string should be "are1 Ho2w y3ou". For that, I have used for...of loop to iterate over a string and used split to convert it into an array of string and then used sort method but I am not getting an output. Can anyone suggest what's wrong in my program?
code ::
function order(words){
let result = "";
for (let value of words) {
result += value;
}
let splited = result.split(" ");
if(words === ""){
return "";
}
return splited.sort((a,b) => a - b);
}
order("Ho2w are1 y3ou");
resultis not defined anywhere?