Sha256: 2f1518be002fbd21a9a9336c03972cf102ab890e85f08ec419220bd4d8d9586a
Contents?: true
Size: 613 Bytes
Versions: 9
Compression:
Stored size: 613 Bytes
Contents
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
9 entries across 9 versions & 1 rubygems