Ad
  • Custom User Avatar

    This is simple and elegant and does what it says on the tin. A+.

  • Default User Avatar

    You should compare strings with the equals method. ==/!= checks for reference equality, equals for value equality.

  • Custom User Avatar

    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...

  • Default User Avatar

    Im getting better, I did the same!

  • Custom User Avatar

    Well, description limits n to 0 <= n < 1000000000. I think gsub(/.../, '\0,') would be shorter and faster than scanning for variable length.

  • Custom User Avatar
  • Default User Avatar

    One char longer than my solution. :P

  • Custom User Avatar

    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.

  • Custom User Avatar

    Yeah, people seem pretty happy to purge the methods entirely.

  • Custom User Avatar

    apparently not many people aliased the methods first, to allow possible usage after our "patches"

  • Custom User Avatar

    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?

  • Custom User Avatar

    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?

  • Custom User Avatar

    The existing user-facing test case either needs a little polish, or could probably be removed entirely. Otherwise, this looks good!

  • Custom User Avatar

    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. :)

  • Custom User Avatar

    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...