Skip to content

Instantly share code, notes, and snippets.

@durrellchamorro
Last active April 21, 2016 18:19
Show Gist options
  • Save durrellchamorro/aced3cf39cab7690c5fe23eb2cfc727f to your computer and use it in GitHub Desktop.
Save durrellchamorro/aced3cf39cab7690c5fe23eb2cfc727f to your computer and use it in GitHub Desktop.
Anagram
class Anagram
def initialize(word)
@actual_word = word
@sorted_word = sort word
end
def match(list)
selected = list.select { |word| sort(word) == @sorted_word }
selected.delete_if { |word| word.downcase == @actual_word }
end
private
def sort(word)
word.downcase.chars.sort
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment