I have an array of objects like this:
var a = [
{ id: 1, score: 1, isCut: false, dnf: false },
{ id: 2, score: 2, isCut: false, dnf: false },
{ id: 3, score: 3, isCut: false, dnf: false },
{ id: 4, score: 4, isCut: false, dnf: false },
{ id: 5, score: 5, isCut: true, dnf: true },
{ id: 6, score: 6, isCut: true, dnf: false },
{ id: 7, score: 7, isCut: true, dnf: false },
{ id: 8, score: 8, isCut: true, dnf: false },
{ id: 9, score: 9, isCut: true, dnf: false },
{ id: 10, score: 0, isCut: false, dnf: false },
{ id: 11, score: -1, isCut: false, dnf: false },
{ id: 12, score: -2, isCut: false, dnf: true },
{ id: 13, score: -3, isCut: false, dnf: false },
{ id: 14, score: -4, isCut: false, dnf: false },
{ id: 15, score: -5, isCut: false, dnf: false },
{ id: 16, score: 10, isCut: true, dnf: false }
];
I need to group and sort the array by the following criteria:
- if
dnf
is true, object goes to bottom; alldnf
-objects should be sorted by score - if
isCut
is true, object goes to bottom, but abovednf
s; allisCut
-objects should be sorted by score - rest should be sorted by
score
, and if the scores are equal, byid