【发布时间】:2013-03-18 21:55:45
【问题描述】:
现在,这是数组,
[1,2,3,4,5,6,7,8,9]
我想要,
[1,2],[2,3],[3,4] upto [8,9]
当我这样做时,我得到 each_slice(2),
[[1,2],[3,4]..[8,9]]
我目前正在这样做,
arr.each_with_index do |i,j|
p [i,arr[j+1]].compact #During your arr.size is a odd number, remove nil.
end
有没有更好的办法??
【问题讨论】: