Skip to content

Latest commit

 

History

History
23 lines (15 loc) · 567 Bytes

split_an_integer_into_an_array.md

File metadata and controls

23 lines (15 loc) · 567 Bytes

Split an Integer into an Array

I needed this for implementing a arabic to roman numeral converter. I needed to split the integer into an array of its digits.

digit = 123
digits = digit.to_s.chars.map(&:to_i)

puts digits.inspect

And if you want to reverse the array, you can use the reverse method.

digit = 123
digits = digit.to_s.chars.reverse.map(&:to_i)

puts digits.inspect

Resources and References