Sha256: 591b7aed16f92ec700d8500c65fe598e87dad0b69418ff47b059e4b4d740eb2c
Contents?: true
Size: 666 Bytes
Versions: 8
Compression:
Stored size: 666 Bytes
Contents
#!/usr/bin/env ruby # frozen_string_literal: true # encoding=utf-8 class Array # Processes each element of the array, yielding the previous, current, and next elements to the given block. # Deletes the current element if the block returns true. # @return [Array] The modified array after conditional deletions. def process_and_conditionally_delete! i = 0 while i < length prev_item = self[i - 1] unless i.zero? current_item = self[i] next_item = self[i + 1] should_delete = yield prev_item, current_item, next_item if should_delete delete_at(i) else i += 1 end end self end end
Version data entries
8 entries across 8 versions & 1 rubygems