Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何在 Ruby (1.9) 中以编程方式创建以下数组。
它遵循模式 7n + 1,我希望它包含 24 个数字。
arr = ["8","15","22","29","36","43","50","57","64","71" ]
使用collect并应用于to_s结果:
collect
to_s
(1..24).collect{|n| (n*7 + 1).to_s}
编辑:抱歉忘记将数字转换为字符串。现在编辑代码。
Array.new(24){|i| (i * 7 + 8).to_s}