Skip to content

Instantly share code, notes, and snippets.

@loganhasson
Last active December 24, 2015 21:39
Show Gist options
  • Save loganhasson/6867556 to your computer and use it in GitHub Desktop.
Save loganhasson/6867556 to your computer and use it in GitHub Desktop.
class Anagram
attr_accessor :word
def initialize(word)
@word = word
end
# def match(anagram_array)
# anagram_array.map do |potential|
# temp_potential = potential.clone
# if potential.length == self.word.length
# self.word.each_char do |c|
# if potential.include?(c)
# potential.sub!(c, "")
# end
# end
# temp_potential if potential.length == 0
# end
# end.compact
# end
# REFACTORED
def match(anagram_array)
anagram_array.select {|item| item.chars.sort == self.word.chars.sort}
end
end
@sarogers
Copy link

sarogers commented Oct 7, 2013

Nice! Very concise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment