I've done an example of how your rule should be with another lib. [dayjs] - Follow the link if you'd like to check it out.
const dayjs = require('dayjs');
let x = [
{ data: dayjs(new Date('01-01-2018')).format('DD-MM-YYYY') } ,
{ data: dayjs(new Date('07-06-1996')).format('DD-MM-YYYY') },
{ data: dayjs(new Date('07-03-1981')).format('DD-MM-YYYY') },
{ data: dayjs(new Date('07-02-2005')).format('DD-MM-YYYY') },
{ data: dayjs(new Date('07-05-2003')).format('DD-MM-YYYY') },
{ data: dayjs(new Date('07-02-2001')).format('DD-MM-YYYY') }
];
var global;
function sortData(){
global = x.sort( (a,b) => {
if (dayjs(a.data).isBefore(dayjs(b.data)))
return -1
else
return 1
})
console.log(global);
}
sortData();
However, what matters to you is the sort that will sort to you according to the last callback function.