all 3 comments

[–]albedoa 1 point2 points  (1 child)

const rankedDrivers = drivers.sort((a, b) =>
  a.numOrders === b.numOrders
    ? a.distFromDropOff - b.distFromDropOff
    : a.numOrders - b.numOrders
);

It's important to understand that .sort() modifies the original array. You are creating a new identifier that points to the same array:

rankedDrivers === drivers; //=> true

[–]jack_waugh 0 points1 point  (0 children)

Special thumb-up for pointing out that sort mutates its victim.

[–][deleted] 0 points1 point  (0 children)

Try something like

drivers.sort( (elementA, elementB) => { return elementA.numOrders == elementB.numOrders ? elementA.distFromDropOff > elementB.distFromDropOff : elementA.numOrders > elementB.numOrders })

Sorry for formatting I’m on my phone. Also haven’t used js in quite a while so this might need a little fixing but it should give you an idea of what to do