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.
我确实有一个范围,例如(1..10). 现在我想从范围中获取每三个元素。对于这里给定的范围,我想作为输出:[4, 7, 10].
(1..10)
[4, 7, 10]
任何短的一个班轮?
适合您的简短表格:
(1..10).step(3).drop(1) #=> [4, 7, 10]