appacademy / prep-work

preparatory material for interviewing with App Academy
291 stars 339 forks source link

Update 06_word_unscrambler.rb #14

Closed tlee418 closed 10 years ago

tlee418 commented 10 years ago

Hi, I am a beginner who applied for app academy. I edited this because the solution can be a bit more simplified. Thanks.

imurchie commented 10 years ago

Have you tried running the test with this?

Two thoughts: (1) Do you want to do the work of str.split("").sort for every word? Does the result ever change? (2) The function is supposed to return an array of anagrams, not just print them out and return nil.

tlee418 commented 10 years ago

Hi imurchie,

Thanks for reading the input. If I modify puts anagrams to return anagrams, would it solve the problem?

I try testing with it and it seems to be getting the result correctly. Please correct me if I am wrong.

Thank you.

imurchie commented 10 years ago

If you return the anagrams array, the tests pass. Otherwise none should work. Are you running the specs as per the instructions?

cd prep-work/coding-test-2/practice-problems
rake spec spec/06_word_unscrambler_spec.rb
cjavdev commented 10 years ago

Prefer readability over one liners.

ruggeri commented 10 years ago

I've checked in a two-liner solution with a comment that the longer version is to be more readable to beginners. :-)