现在,这是数组,
[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
有没有更好的办法?
https://stackoverflow.com/questions/15682223
复制相似问题