I am trying to sort an array e.g.
arr = ["Joe1,345", "James,1002", "Bill,24"].
I need to order them by number descending but there could be a different amount of numbers on the end. I have tried a bubble sort:
function bubbleSort(a) {
var swapped;
do {
swapped = false;
for (var i=0; i < a.length-1; i++) {
if (a[i] > a[i+1]) {
var temp = a[i];
a[i] = a[i+1];
a[i+1] = temp;
swapped = true;
}
}
} while (swapped);
return a;
}
But that didn't work - does anyone know how to achieve this? I've looked at other people doing a similar thing but their answers seem to only have a constant letter in front.
Many Thanks
function compareNumbers(a, b) { return a.split(",")[1] - b.split(",")[1]; }['Joe,100', 'Ann,100']?