Sha256: dee406a2212bf505ddaaaeec8678a07ca6a53e4910434ceb8321dc266678c7fc

Contents?: true

Size: 563 Bytes

Versions: 3

Compression:

Stored size: 563 Bytes

Contents

# frozen_string_literal: true

module Masososo
  class Indexer
    # rubocop:disable Lint/ShadowingOuterLocalVariable
    def self.index(sets, including_self)
      sets.reduce({}) do |indexes, chars|
        chars.each_with_object(indexes) do |char, indexes|
          adding = including_self ? chars.dup : (chars - [char])

          if indexes[char].nil?
            indexes[char] = adding
          else
            indexes[char].concat(adding).uniq!
          end
        end
      end
    end
    # rubocop:enable Lint/ShadowingOuterLocalVariable
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
masososo-0.0.3 lib/masososo/indexer.rb
masososo-0.0.2 lib/masososo/indexer.rb
masososo-0.0.1 lib/masososo/indexer.rb