Alright, so I have an array of objects that includes null values for a certain property.
The object looks roughly like this for sorting purposes... (40 elements, but this will suffice...).
It needs to be sorted based on roulette descending (with roulette sometimes being null), then novelty, then popularity.
My head is getting a bit crushed.
This works to sort the roulette in descending, but how do I need to extend it to include the other two criteria?
Object:
[
{
title: 'one',
popularity: 4,
novelty: 3
},
{
title: 'two',
popularity: 1
novelty: 4
},
{
title: 'three',
popularity: 5,
novelty: 3,
roulette: 0
},
{
title: 'four',
popularity: 5,
novelty: 3,
roulette: 1
}
]
Partially working function:
object.sort(function(a, b) {
if (a['roulette'] == null) return 1
if (b['roulette'] == null) return -1
if (a['roulette'] === b['roulette']) return 0
return b.roulette > a.roulette ? 1 : -1
});
nullgo?nullvalues in roulette or is roulette just not set?