← Back to challenges

Let's Sort This Array!

JavaScriptHardarraysnumberssorting

Instructions

Create a function that takes an array of numbers arr, a string str and return an array of numbers as per the following rules:

  • "Asc" returns a sorted array in ascending order.
  • "Des" returns a sorted array in descending order.
  • "None" returns an array without any modification.

Examples

ascDesNone([4, 3, 2, 1], "Asc" ) ➞ [1, 2, 3, 4]

ascDesNone([7, 8, 11, 66], "Des") ➞ [66, 11, 8, 7]

ascDesNone([1, 2, 3, 4], "None") ➞ [1, 2, 3, 4]

Notes

N/A

javascript
Loading editor…
⌘ ↡ to run
Walks through the solution with reasoning and edge cases.
Next: All About Anonymous Functions: Adding β†’