Ranking Helpers
JavaScript
20 pts
Ranking Helpers
Write four arrow functions that never change the array they get (use toSorted()):
ascending(nums)returns a copy sorted from small to big.descending(nums)returns a copy sorted from big to small.topThree(times)returns the three smallest times (useascendingandslice).alphabetical(names)returns a copy of the names in A–Z order.
The starter prints:
[ 55, 57, 58 ] [ 10, 7, 3 ] [ "Abel", "Senait", "Yonas" ] [ 58, 61, 55, 63, 57 ]
Checklist
- Write
ascendinganddescendingfor numbers. - Write
topThree. - Write
alphabetical. - Never change the original arrays.
- The four lines are printed.
🔑 Solution
If you view the solution before passing, you earn half points for this exercise. You still need to type it and press Check to finish.
How it works, step by step
Point at a step to highlight its lines. Type the solution yourself and press Check answer to finish.
