Sorting the Rota for the Wiki

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.

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.