Sha256: 079627a9a227605f99146c556924e92f8c3471cda24634e096d79bea3e1a82e1
Contents?: true
Size: 625 Bytes
Versions: 3
Compression:
Stored size: 625 Bytes
Contents
class Array # Iterate over each slice where the last n values of a preceding slice # overlap with the first n values of the following slice. The value of n # is specified by the second `overlap` argument. # # a, r = [1,2,3,4,5], [] # a.each_overlap(2,1) { |x,y| r << [x,y] } # r # => [[1,2],[2,3],[3,4],[4,5]] # # Returns nothing. def each_overlap(slice_size, overlap) if block_given? i = 0 while i + slice_size <= length yield slice(i...i+slice_size) i += (slice_size - overlap) end else to_enum(:each_overlap, slice_size, overlap) end end end
Version data entries
3 entries across 3 versions & 2 rubygems
Version | Path |
---|---|
facets-glimmer-3.2.0 | lib/core/facets/array/each_overlap.rb |
facets-3.1.0 | lib/core/facets/array/each_overlap.rb |
facets-3.0.0 | lib/core/facets/array/each_overlap.rb |