Sha256: 1472a0afb813d716e61b73892523b6d5033394745a54febe9d7ba4cb8e7f635a
Contents?: true
Size: 649 Bytes
Versions: 148
Compression:
Stored size: 649 Bytes
Contents
module BookKeeping VERSION=2 end class Anagram attr_reader :subject def initialize(word) @subject = AnagramSubject.new(word) end def match(candidates) candidates.select do |candidate| subject.anagram_of? candidate end end end class AnagramSubject attr_reader :subject def initialize(subject) @subject = subject end def anagram_of?(word) !duplicate?(word) && fingerprint == canonicalize(word) end def duplicate?(word) word.downcase == subject.downcase end def canonicalize(word) word.downcase.chars.sort end def fingerprint @fingerprint ||= canonicalize(subject) end end
Version data entries
148 entries across 148 versions & 1 rubygems