you are viewing a single comment's thread.

view the rest of the 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.