Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/chinese_vocab/core_ext/array.rb

Instance Method Summary collapse

Instance Method Details

#overlap_pairsObject

Input: [1,2,3,4,5] Output: [[1, 2], [2, 3], [3, 4], [4, 5]]



7
8
9
10
11
12
13
# File 'lib/chinese_vocab/core_ext/array.rb', line 7

def overlap_pairs
  second = self.dup.drop(1)
  self.each_with_index.inject([]) {|acc,(item,i)|
    acc << [item,second[i]]  unless second[i].nil?
    acc
  }
end