Last active
December 25, 2015 07:19
-
-
Save pzula/6938430 to your computer and use it in GitHub Desktop.
Anagram shenanagins
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 | |
attr_reader :starting_word | |
def initialize(starting_word) | |
@starting_word = starting_word | |
end | |
def starting_letters | |
starting_word.chars | |
end | |
def starting_letters_alphabetized | |
starting_letters.sort | |
end | |
def match(comparison_words) | |
matches = [] | |
comparison_words.each do |word| | |
if equal_length?(word) && not_the_same_word?(word) && same_characters?(word) | |
matches << word | |
end | |
end | |
return matches | |
end | |
def equal_length?(word) | |
starting_word.length == word.length | |
end | |
def not_the_same_word?(word) | |
starting_word != word | |
end | |
def same_characters?(word) | |
word.chars.sort == starting_letters_alphabetized | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment