Skip to content

Latest commit

 

History

History
25 lines (21 loc) · 523 Bytes

convert_number_to_reversed_array_of_digits.md

File metadata and controls

25 lines (21 loc) · 523 Bytes

Description

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.

Example(Input => Output):

35231 => [1,3,2,5,3]
0 => [0]

My Solution

def digitize(n)
  n.to_s.reverse.chars.map(&:to_i)
end

Better/Alternative solution from Codewars

def digitize(n)
  n.digits
end