Sort with a comparator (default sort is lexicographic!).
Given const nums = [10, 2, 33, 4]; sort ascending with .sort((a, b) => a - b) and log the result.
Note: without a comparator, JS sorts by string and gives [10, 2, 33, 4] → [10, 2, 33, 4]. Always pass a comparator for numbers.
Sign in to save your code and track progress across devices.