I am trying to sort an array in a decending fashion by the property commonVotes. Sorting is going somewhat well except the last element (Pride) after being sorted isn't going in the correct place.
Array before sorting:
[
{
"uuid": "4bf84d40-476e-11ea-87f1-f1c0fe90cd16",
"name": "Pride",
"createdAt": "2020-02-04T16:49:23.475Z",
"updatedAt": "2020-02-04T16:49:23.475Z",
"commonVotes": 70,
"deadlyVotes": 76
},
{
"uuid": "4bf84d41-476e-11ea-87f1-f1c0fe90cd16",
"name": "Lust",
"createdAt": "2020-02-04T16:49:23.475Z",
"updatedAt": "2020-02-04T16:49:23.475Z",
"commonVotes": 17,
"deadlyVotes": 105
},
{
"uuid": "4bf84d42-476e-11ea-87f1-f1c0fe90cd16",
"name": "Glutony",
"createdAt": "2020-02-04T16:49:23.475Z",
"updatedAt": "2020-02-04T16:49:23.475Z",
"commonVotes": 40,
"deadlyVotes": 21
},
{
"uuid": "4bf84d43-476e-11ea-87f1-f1c0fe90cd16",
"name": "Envy",
"createdAt": "2020-02-04T16:49:23.475Z",
"updatedAt": "2020-02-04T16:49:23.475Z",
"commonVotes": 82,
"deadlyVotes": 75
}
]
Array after sorting:
[
{
"uuid": "4bf84d43-476e-11ea-87f1-f1c0fe90cd16",
"name": "Envy",
"createdAt": "2020-02-04T16:49:23.475Z",
"updatedAt": "2020-02-04T16:49:23.475Z",
"commonVotes": 82,
"deadlyVotes": 75
},
{
"uuid": "4bf84d42-476e-11ea-87f1-f1c0fe90cd16",
"name": "Glutony",
"createdAt": "2020-02-04T16:49:23.475Z",
"updatedAt": "2020-02-04T16:49:23.475Z",
"commonVotes": 40,
"deadlyVotes": 21
},
{
"uuid": "4bf84d41-476e-11ea-87f1-f1c0fe90cd16",
"name": "Lust",
"createdAt": "2020-02-04T16:49:23.475Z",
"updatedAt": "2020-02-04T16:49:23.475Z",
"commonVotes": 17,
"deadlyVotes": 105
},
{
"uuid": "4bf84d40-476e-11ea-87f1-f1c0fe90cd16",
"name": "Pride",
"createdAt": "2020-02-04T16:49:23.475Z",
"updatedAt": "2020-02-04T16:49:23.475Z",
"commonVotes": 70,
"deadlyVotes": 76
}
]
Sorting code:
sins.sort((a, b) => {
return (a.commonVotes > b.commonVotes) ? 1 : -1
})
How do I fix this? Is it a bug placed by the Illuminati that is forver bugged?