I buit this code to sort the array values acording to car
value.
const arr = [
{
car: 'audi',
age: 2015
},
{
car: 'bmw',
age: 1999
},
{
car: 'alfa',
age: 2019
},
];
function createSort(property) {
return function compareString(a,b) {
return a[property] < b[property]
}
}
const sortByTitle = createSort('car');
arr.sort(sortByTitle);
console.log(arr);
I can't figure out why it does not sort.
What is the issue?