【发布时间】:2015-04-12 17:47:19
【问题描述】:
对于数字n,我只能想到
array_of_digits = n.to_s.split('').map(&:to_i)
还有更优雅的方法吗?
【问题讨论】:
-
@itdoesntwork 的
each_byte方法很有趣,但我认为大多数 Rubiests 会使用你所拥有的,尽管我认为string_of_digits = n.to_s.each_char.map(&:to_i)是一个小的改进,因为它不会创建中间数组。