Convert number to reversed array of digits
Given a random non-negative number, you have to return the digits of this number within an array in reverse order.
const digitize = (n: number): number[] => {
return String(n).split('').reverse().map(n => Number(n));
};
console.log(digitize(12345));
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))
}
def digitize(n):
return [int(x) for x in str(n)[::-1]]
print(digitize(12345))
function digitize($n) {
return array_map('intval', str_split(strrev((string)$n)));
}
print_r(digitize(12345));
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