現在,這是一個數組,紅寶石數組訪問連續2個(鏈接)元素在時間
[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
有沒有更好的方法?
的[是否有一個算法從陣列提取二重奏值和操作可能重複在他們?](http://stackoverflow.com/questions/6075266/is-there-an-algorithm-to-extract-values-in-duets-from-an-array-and-operate-over) – jvnill