How to convert number to array of digits in Ruby

1 Answer

0 votes
n = 38729

arr = n.digits
 
print arr, "\n"

puts(arr[0])
puts(arr[1])
puts(arr[2])
puts(arr[3])
puts(arr[4])
 

 
 
#
# run:
# 
# [9, 2, 7, 8, 3]
# 9
# 2
# 7
# 8
# 3
#

 



answered Oct 17, 2021 by avibootz
...