HR wants the names from this Monday’s rota in alphabetical order for the wiki. Dev must still carry the pager next, so sorting the display must preserve the queue. Python’s sorted(rota) already expresses that choice. In JavaScript, you’ll use an array method that makes the same promise.
Keep the Rota With .toSorted()
JavaScript puts both sorting tools on the array. Choose according to whether the original order must survive:
| Python | JavaScript | Result |
|---|---|---|
sorted(rota) |
rota.toSorted() |
A new sorted list or array |
rota.sort() |
rota.sort() |
Reorders the original |
Python’s .sort() returns None, while JavaScript’s returns the same array it reordered. Watch out: const wiki = rota.sort() makes both names refer to that array and puts Bea first in next Monday’s queue.