Last active
April 21, 2016 18:19
-
-
Save durrellchamorro/aced3cf39cab7690c5fe23eb2cfc727f to your computer and use it in GitHub Desktop.
Anagram
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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