Skip to content

Instantly share code, notes, and snippets.

@yoosuf
Created October 31, 2018 05:56
Show Gist options
  • Save yoosuf/e0edca5313d80aea41254e7907acdecd to your computer and use it in GitHub Desktop.
Save yoosuf/e0edca5313d80aea41254e7907acdecd to your computer and use it in GitHub Desktop.
Simple Anagram with Ruby
def anagram(str1, str2)
if str1.nil? || str2.nil? || str1.empty? || str2.empty?
return false
end
demo1 = str1.split("").sort
demo2 = str2.split("").sort
test1 = noirmalise(demo1)
test2 = noirmalise(demo2)
test1.join == test2.join
end
def noirmalise (data)
data.join.scan(/[a-z]/)
end
# puts '===== Positive cases ======'
puts anagram('google', 'ggoole')
# puts '===== Negative cases ======'
puts anagram('google', 'yahoo')
puts anagram('', '')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment