Skip to content

Comments

Jack Chester Solutions#81

Open
jack-chester wants to merge 1 commit intopaircolumbus:masterfrom
jack-chester:master
Open

Jack Chester Solutions#81
jack-chester wants to merge 1 commit intopaircolumbus:masterfrom
jack-chester:master

Conversation

@jack-chester
Copy link

# Implement this in such a way that when called below, detect_anagram will result in true or false.
def canonical(word)
word = word.upcase
word.split("").sort.to_s #split into characters, sort alphabetically, push back into one string.
Copy link
Member

Choose a reason for hiding this comment

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

String#chars is a bit simpler way to split a string into characters.

Copy link
Member

Choose a reason for hiding this comment

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

Is that to_s at the end giving you back the string you think it is? Do we even need this method to return a string?

Copy link
Author

@jack-chester jack-chester Jun 16, 2017

Choose a reason for hiding this comment

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

Ah, each character is individually being converted to a string. Array#join would have been better, although looking back I didn't even need to join the string at all to determine whether or not it was an anagram.

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