The Auto-Organizer

Medium+25 XP

Mission Briefing

The Grand Library's automated sorting machine broke and scattered numbered scrolls everywhere! You must rebuild the logical mechanism to sort the numbers properly.

The Concept: Array Sorting

By default, the .sort() method converts elements into strings, then compares their UTF-16 values. This completely breaks for numbers (e.g., 10 sorts before 2)! To fix this, you must provide a compare function: (a, b) => a - b sorts numbers in ascending order.

The Objective

Your function receives an array of scrambled numbers.

  1. Sort the array in ascending order (lowest to highest).
  2. Return the freshly sorted array. (Note: .sort() mutates the original array, which is perfectly fine here!)

01EXAMPLE 1

Inputnumbers = [40, 1, 5, 20]
Output[1, 5, 20, 40]

Constraints

  • Use the .sort() method with a compare function.
CoreArrays
JavaScript
Loading...
3 Hidden

Input Arguments

numbers[40,1,5,20]

Expected Output

[1,5,20,40]

Click RUN to test your solution