Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
This is simple and elegant and does what it says on the tin. A+.
You should compare strings with the
equals
method.==
/!=
checks for reference equality,equals
for value equality.How would I "fix" it?
I'm extremely new to Java and 'intern' is something I just learned about from looking it up based on your comment...
Im getting better, I did the same!
Well, description limits n to 0 <= n < 1000000000. I think gsub(/.../, '\0,') would be shorter and faster than scanning for variable length.
nice
One char longer than my solution. :P
It would be nice for the downvoter of the comment above to share some reasoning for their vote? My understanding was that downvotes were typically used to flag posts. Either way, anonymously downvoting is lame.
Yeah, people seem pretty happy to purge the methods entirely.
apparently not many people aliased the methods first, to allow possible usage after our "patches"
I think I see what you're driving at - the inject method has to explicitly pass the hash along to the next iteration, while the each_with_object method does that for us. But I think I'd hesitate to call one less crufty than the other; each_with_object doesn't need a second statement in the block, but inject seems to keep the variables in a more straightforward order and is a few characters shorter. I ran benchmarks but they compare very closely for speed.
After looking at it, I'd say that the two solutions are pretty much equivalent and I don't see a strong case to favor one over the other. Is there a point I've failed to consider?
I'm familiar with #each_with_object, though I'll admit it doesn't often come to mind. That having been said, I don't see an obvious way to clean up the code with it - where would you apply each_with_object?
The existing user-facing test case either needs a little polish, or could probably be removed entirely. Otherwise, this looks good!
Fun kata! I think it's very nearly ready for production, but it needs a small adjustment to the test case messages - specifically, it seems like you're outputting instructions or advice for passing tests when you mean to output it only for failed cases (e.g., "including Enumerable is cheating," or "why are you messing with #count?"). Tweak those to only show up in failing cases and I think this is ready for prime time. :)
One small suggestion - if I only have one student, then technically they "all" have the same amount of money. I don't disagree with the test suite rejecting that answer, but I do think the instructions need a line about what you expect when only one student is presented.
Loading more items...