Sort Numbers in Ascending Order

Published by Николай in

Create a function that takes an array of numbers and returns a new array, sorted in ascending order (smallest to biggest).

  • Sort the numbers array in ascending order.
  • If the function's argument is null, an empty array, or undefined; return an empty array.
  • Return a new array of sorted numbers.

Examples

SortNumsAscending([1, 2, 10, 50, 5]) ➞ [1, 2, 5, 10, 50]

SortNumsAscending([80, 29, 4, -95, -24, 85]) ➞ [-95, -24, 4, 29, 80, 85]

SortNumsAscending(null) ➞ []

SortNumsAscending([]) ➞ []

Notes

Test input can be positive or negative.

Watch a quick demo on how Edabit works.