Q:

How to short on desending order using a object property using parseFloat?

I have the following test code
var arr = [{
    EmployeeInfo: [{
        annualWage: "24000"
    }],
    name: "Tim",
    surname: "Jones",
    id: "1111"
}, {
    EmployeeInfo: [{
        annualWage: "52000"
    }],
    name: "Terry",
    surname: "Phillips",
    id: "2222"
}];

console.log(arr);

arr.sort(function (a, b) {

    return parseFloat(a.EmployeeInfo[0].annualWage) - parseFloat(b.EmployeeInfo[0].annualWage);
});

console.log(arr);

I want to sort the array by annualWage with the highest earner at the beginning. 
Can't seem to get it to work... what obvious thing am I missing?

A:

You just need to reverse the order. The rules are as follows:

If compareFunction is supplied, the array elements are sorted according to the return value of the compare function. If a and b are two elements being compared, then:

If compareFunction(a, b) is less than 0, sort a to a lower index than b, i.e. a comes first.
If compareFunction(a, b) returns 0, leave a and b unchanged with respect to each other, but sorted with respect to all different
  elements. Note: the ECMAscript standard does not guarantee this
  behaviour, and thus not all browsers (e.g. Mozilla versions dating
  back to at least 2003) respect this.
If compareFunction(a, b) is greater than 0, sort b to a lower index than a.
compareFunction(a, b) must always return the same value when given a specific pair of elements a and b as its two arguments. If
  inconsistent results are returned then the sort order is undefined.

So basically:
arr.sort(function(a, b) {
  return parseFloat(b.EmployeeInfo[0].annualWage) - parseFloat(a.EmployeeInfo[0].annualWage);
});

