I have an array of objects similar to...
[
{
date: "26/11/2016"
hourlyRate: 50
hoursWorked: 10
name: "Mr G"
natInsNumber: "GG845893G"
},
{
date: "14/10/2016"
hourlyRate: 50
hoursWorked: 10
name: "Mr A"
natInsNumber: "GG845893G"
},
{
date: "11/09/2016"
hourlyRate: 50
hoursWorked: 10
name: "Mr H"
natInsNumber: "GG845893G"
},
{
date: "26/10/2016"
hourlyRate: 50
hoursWorked: 10
name: "Mr L"
natInsNumber: "GG845893G"
}
]
I need to sort this list based on the most recent dates.
Based on similar problems I have seen this is my code for the solution, the array is being passed in as the records
argument...
function sortRecords (records) {
var sorted = records.sort(function(a, b){
return new Date(a.date) - new Date(b.date);
});
return sorted;
}
Can anyone advise on why this is not working? I am just getting back the same unsorted array....