I am trying to sort a complex object based off of a specific key placement
. That key is usually either a numerical values 1
, 2
, 3
, etc. It can also indicate a tie by having 1T
, 2T
, 3T
, etc. But, if a team did not finish or was disqualified, their placement will be marked as DQ
or DNF
. I want any team with placement == DQ || placement == DNF
to be sorted at the end of the list.
The object looks like this:
placements = {
"c111c16d-8132-11eb-8fe2-0800273120f7": {
"team": "St Olaf",
"team_location": null,
"team_season_id": "c111c16d-8132-11eb-8fe2-0800273120f7",
"event_team_placement_id": 8343,
"seed": "8",
"placement": "DNF",
"spirit_score": "12.33",
"won_spirit_tie_breaker": null,
"won_spirit": null
},
"c118f96a-8132-11eb-8fe2-0800273120f7": {
"team": "Bates",
"team_location": null,
"team_season_id": "c118f96a-8132-11eb-8fe2-0800273120f7",
"event_team_placement_id": 8344,
"seed": "12",
"placement": "1",
"spirit_score": "14.20",
"won_spirit_tie_breaker": null,
"won_spirit": null
},
"c14b9603-8132-11eb-8fe2-0800273120f7": {
"team": "Puget Sound",
"team_location": null,
"team_season_id": "c14b9603-8132-11eb-8fe2-0800273120f7",
"event_team_placement_id": 8352,
"seed": "2",
"placement": "3T",
"spirit_score": "11.83",
"won_spirit_tie_breaker": null,
"won_spirit": null
},
"c1459d8c-8132-11eb-8fe2-0800273120f7": {
"team": "Lehigh",
"team_location": null,
"team_season_id": "c1459d8c-8132-11eb-8fe2-0800273120f7",
"event_team_placement_id": 8351,
"seed": "0",
"placement": "3T",
"spirit_score": "9.80",
"won_spirit_tie_breaker": null,
"won_spirit": null
},
"c164df69-8132-11eb-8fe2-0800273120f7": {
"team": "Williams",
"team_location": null,
"team_season_id": "c164df69-8132-11eb-8fe2-0800273120f7",
"event_team_placement_id": 8356,
"seed": "2",
"placement": "5T",
"spirit_score": "13.25",
"won_spirit_tie_breaker": null,
"won_spirit": null
},
"c15e97ae-8132-11eb-8fe2-0800273120f7": {
"team": "Wesleyan",
"team_location": null,
"team_season_id": "c15e97ae-8132-11eb-8fe2-0800273120f7",
"event_team_placement_id": 8355,
"seed": "5",
"placement": "5T",
"spirit_score": "10.50",
"won_spirit_tie_breaker": null,
"won_spirit": null
},
"c15866e0-8132-11eb-8fe2-0800273120f7": {
"team": "Rensselaer Polytech",
"team_location": null,
"team_season_id": "c15866e0-8132-11eb-8fe2-0800273120f7",
"event_team_placement_id": 8354,
"seed": "8",
"placement": "5T",
"spirit_score": "14.80",
"won_spirit_tie_breaker": null,
"won_spirit": null
},
"c151d3f9-8132-11eb-8fe2-0800273120f7": {
"team": "Mount Holyoke",
"team_location": null,
"team_season_id": "c151d3f9-8132-11eb-8fe2-0800273120f7",
"event_team_placement_id": 8353,
"seed": "12",
"placement": "5T",
"spirit_score": "11.60",
"won_spirit_tie_breaker": null,
"won_spirit": null
},
}
and my current function to sort it:
sortByFinish(): void{
let sorted = this.placements.sort(
(a,b) => (parseInt(a.placement) - parseInt(b.placement))
)
this.placements = sorted
}
This works for any placement that is numerical or has a tie, but it does not work when the placement is DQ
or DNF
. How can I handle those cases so they sorted at the end of the list?