From d0ddf18480e9d396817cfbdd7423ff4d66c67c86 Mon Sep 17 00:00:00 2001 From: mshecket Date: Sun, 10 Nov 2019 19:51:59 -0500 Subject: [PATCH 1/2] Done! --- anagram_detector.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/anagram_detector.rb b/anagram_detector.rb index 36c0724..952ea86 100644 --- a/anagram_detector.rb +++ b/anagram_detector.rb @@ -1,5 +1,6 @@ # Implement this in such a way that when called below, detect_anagram will result in true or false. def canonical(word) + return word == word.reverse end def detect_anagram(word1, word2) From 5829017f1a929763952f7f79906d1cc8b57fc260 Mon Sep 17 00:00:00 2001 From: Mike Shecket Date: Mon, 11 Nov 2019 08:51:53 -0500 Subject: [PATCH 2/2] Now actually checking for anagrams I was mistakenly checking for palindromes instead of anagrams, but now I've got it working correctly. --- anagram_detector.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/anagram_detector.rb b/anagram_detector.rb index 952ea86..38aed9a 100644 --- a/anagram_detector.rb +++ b/anagram_detector.rb @@ -1,6 +1,12 @@ # Implement this in such a way that when called below, detect_anagram will result in true or false. def canonical(word) - return word == word.reverse + # Change the word to all lowercase, then + # separate it into an array of the characters + # contained in the string, and finally sort + # that array so that any word that's an + # anagram of this word will have the same + # canonical representation. + return word.downcase.chars.sort end def detect_anagram(word1, word2)