Kata of the Day #19

Sort Numbers

kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
Kata of the Day #19

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.

TypeScript


function sortNumbers(nums: number[]): number[] {
    return nums.sort((a, b) => a - b);
}

console.log(sortNumbers([1, 10, 2]));

Go


package main

import (
    "fmt"
    "sort"
)

func sortNumbers(nums []int) []int {
    sort.Ints(nums)
    return nums
}

func main() {
    fmt.Println(sortNumbers([]int{1, 10, 2}))
}

Python


def sort_numbers(nums):
    return sorted(nums)

print(sort_numbers([1, 10, 2]))

PHP


function sortNumbers($nums) {
    sort($nums);
    return $nums;
}

print_r(sortNumbers([1, 10, 2]));

Go to Kata
ByCesar Kohl

Need some help?

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
budget
budget
budget
budget
budget
budget
budget
budget
budget
budget

Subscribe to our newsletter

subscribe
subscribe
subscribe
subscribe
subscribe
subscribe
subscribe
subscribe
subscribe
subscribe