🔢 Quick tip: if you're sorting an array in JS and keep forgetting how to write the compare functions (like I do), here's a mnemonic device:
(a, z) => a - z // ascending, like "a to z"
(a, z) => z - a // descending, like "z to a"
Hope this helps someone!
ALT let nums = [8, 6, 7, 5, 3, 0, 9, 2, 4, 1];
// Ascending, like "a to z"
nums.sort((a, z) => a - z);
// Descending, like "z to a"
nums.sort((a, z) => z - a);
// ℹ️ Remember: array.sort() mutates the array!