Kata of the Day #13

Convert number to reversed array of digits

kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
Kata of the Day #13

Given a random non-negative number, you have to return the digits of this number within an array in reverse order.

TypeScript


const digitize = (n: number): number[] => {
    return String(n).split('').reverse().map(n => Number(n));
};

console.log(digitize(12345));

Go


package main

import "fmt"

func digitize(n int) []int {
    var result []int

    for n > 0 {
        result = append(result, n % 10)
        n /= 10
    }

    return result
}

func main() {
    fmt.Println(digitize(12345))
}

Python


def digitize(n):
    return [int(x) for x in str(n)[::-1]]

print(digitize(12345))

PHP


function digitize($n) {
    return array_map('intval', str_split(strrev((string)$n)));
}

print_r(digitize(12345));

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