I have written the following code which is working when there is alphabetic data, how can I make it work uniquely irrespective of alphabets or numbers
function sortList(selectId) {
var options = $(selectId + ' option');
var arr = options.map(function(_, o) {
return {
t: $(o).text(),
v: o.value
};
}).get();
arr.sort(function(o1, o2) {
return o1.t > o2.t ? 1 : o1.t < o2.t ? -1 : 0;
});
options.each(function(i, o) {
o.value = arr[i].v;
$(o).text(arr[i].t);
});
}
$(document).ready(function() {
sortList("#whatever");
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select id='whatever'>
<option value='1'>1</option>
<option value='2'>2</option>
<option value='10'>10</option>
</select>
It is getting sorted as 1,10,2
where I am looking it like 1,2,10
. How to make this function unique to work for all scenarios