Skip to content

Comments

completed CMM activity#70

Open
lmieu wants to merge 2 commits intopaircolumbus:masterfrom
lmieu:lmusie
Open

completed CMM activity#70
lmieu wants to merge 2 commits intopaircolumbus:masterfrom
lmieu:lmusie

Conversation

@lmieu
Copy link

@lmieu lmieu commented Jan 13, 2017

@@ -1,5 +1,7 @@
# Implement this in such a way that when called below, detect_anagram will result in true or false.
def canonical(word)
word.downcase!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modifying the input is typically unexpected.

puts "What word do you want to check?"
word = gets.chomp
canonical_version_of_word = canonical(word)
puts "The canonical version of #{word} is #{canonical_version_of_word}."
What word do you want to check?
ALLCAPSWORD
The canonical version of allcapsword is ["a", "a", "c", "d", "l", "l", "o", "p", "r", "s", "w"].

# Implement this in such a way that when called below, detect_anagram will result in true or false.
def canonical(word)
down = word.downcase
canon = down.split("").sort_by{|char| char}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The String#chars method is a bit clearer than split("").

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.sort_by{|char| char} is equivalent to just .sort.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants