I have an array that could be either just a list of strings or it could be just a list of strings of numbers, i.e array could be like below
let array = ['abc','def','aef','gfh']
or
let array = ['123','456','192','412']
I want to have sort function that can handle the natural sort in either of these case, below code doesn't seem to handle the string of numbers, is there a way to handle this?
array.sort((a,b) => {
if(a > b) return 1;
if(a < b) return -1;
return 0;
});