250741 is what i want to convert to an int array in ruby

To convert the number 250741 into an integer array in Ruby, you can use the digits method:

main.rb
number = 250741
array = number.digits.reverse
46 chars
3 lines

Here, the digits method returns an array containing the digits of the number in reverse order. To get the digits in the original order, we can use the reverse method.

The resulting array will be [2, 5, 0, 7, 4, 1], with each digit of the number being an element in the array.

related categories

gistlibby LogSnag