Sort Numbers
Finish the solution so that it sorts the passed in array of numbers. If the function passes in an empty array or null/nil value then it should return an empty array.
function sortNumbers(nums: number[]): number[] {
return nums.sort((a, b) => a - b);
}
console.log(sortNumbers([1, 10, 2]));
package main
import (
"fmt"
"sort"
)
func sortNumbers(nums []int) []int {
sort.Ints(nums)
return nums
}
func main() {
fmt.Println(sortNumbers([]int{1, 10, 2}))
}
def sort_numbers(nums):
return sorted(nums)
print(sort_numbers([1, 10, 2]))
function sortNumbers($nums) {
sort($nums);
return $nums;
}
print_r(sortNumbers([1, 10, 2]));
Go to Kata
Want us to give you some help with your business? No problem, here's a video on who we can help, and how, along with our calendar so you can book in a call to discuss us working together.
Let's see