Cook
Sort array of numbers (asc)
const sorted = [...positions].sort((a, b) => a - b)
Sort array of strings (alphabetically)
list.sort(function (a, b) {
return a > b ? 1 : -1;
})
Sort by multiple properties
list.sort((a, b) => {
if (b.ratings !== a.ratings) {
// first sort by ratings (desc)
return b.ratings - a.ratings
} else {
// then sort by id (desc)
return b.id - a.id
}
})
Sort by date (as string)
array.sort((a,b) => new Date(b.date).getTime() - new Date(a.date).getTime();
);