I have an array of objects that i would like to order by several properties.
Im going to showcase a single element of the array
var ele = {
id: INT, various,
priority: INT 1 - 10,
shooterid: INT various,
targetid: INT various,
flight: BOOL
}
i would like to order the array according to some criteria and i can do the sort by priority, shooter and target by using
if (a.priority != b-priority){
return a-priority - b-priority;
else if a.shooterid != b.shooterid){
return a.shooterid - b. shooterid
}
else return a.targetid - b.targetid
However, i also want to sort by flight and i would like to all elements with flight = true to be sorted LAST in addition to the above sort.
I tried if (a.flight){return -1/0/1} a the very top of the above if/self (adding else to the formerly if) but it didnt work...
How can i extend the sort to include for the BOOL prop ?
flightcomparison the first thing you do. If theflightproperties are different, then nothing else matters. You say that "didn't" work, but it will work; describe what went wrong or else nobody can really help you.return -1/0/1? That's negativeInfinity(negative one divided by zero divided by one) -- is that what you intended? Or do you mean you tried each of those values separately and nothing worked?flightlike anything else, because if you return any value unconditionally whenflightis true then you can’t compare within the list of elements that haveflight.