no digits in ruby
12345.digits #=> [5, 4, 3, 2, 1]
so digits.first is correct
Ah yes, somehow I was thinking this would have the same order as chars.to_a, but it doesn't, so you can easily get back the number:
[5, 4, 3, 2, 1].each.with_index.reduce(0) do |result, (n, i)|
result + n * 10 ** i
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.