Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions anagram_detector.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Implement this in such a way that when called below, detect_anagram will result in true or false.
def canonical(word)
# 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
Copy link

Choose a reason for hiding this comment

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

Looks a lot better. Nice find on chars.

To make the ruby more idiomatic, omit return whenever possible.

I personally also find this sort of comment unhelpful - you're basically just explaining how the language works to the reader. Your mileage may vary on this one though.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks very much for the feedback!

I do tend to err on the side of verbose when it comes to comments--still getting a feel for it and what the expectations are for a professional developer. I'm coming from an education background, so I do have an impulse to explain everything as if it were new to the reader.

Copy link

Choose a reason for hiding this comment

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

Got it. There is a range of commenting styles for professional developers, but I think it's safe to say that this much explanation would be well outside the norm. My personal style is to put all my energy into choosing helpful names for variables, methods, and classes, and structuring things in a way that is easy to understand. If I feel like I need a comment for someone else to understand it, I take that as a sign that I need to work harder at my naming/structure. If work harder at it and I still feel like it won't make sense without the comment, then I leave it. But again that's just one way of doing things.

end

def detect_anagram(word1, word2)
Expand Down