Ad
  • Custom User Avatar

    No random tests.

  • Custom User Avatar

    No sample tests.

  • Custom User Avatar
  • Custom User Avatar

    @Wei-LiangChew I'm a little late but then the while loop will iterate over with n - 1 = 8 (and so on)

  • Custom User Avatar

    But what if the largest 5-digit number in digits doesn't start with 9?

  • Custom User Avatar

    Hey Ricardo! Yeah I thought it was you. I just started codewars :) Thanks man. Hope you're doing good as well!

  • Custom User Avatar

    Hey Freddy, what's up bro? This is Ricardo, from Ayu!

    Hope you're well

    I just got it, thanks!

  • Custom User Avatar

    I think it means that if a 'Bag' object does not have any elements in it, then it should not blow up the tests. So your code should still work even for 'Bag' objects that happen to not have anything in it.

  • Custom User Avatar

    I don't know what it means with "Empty bags should pass all tests.", anybody?

    I also can't see the output for any kata.

    Thanks!

  • Custom User Avatar

    Nice one-liner. The Array allocated by split('') or chars gives this algorithm O(n) space complexity, it's possible to solve this with O(1) space complexity. All voted on solutions share this problem.

  • Default User Avatar

    Great Job, I just started to learn regex, and I find it really useful ( rather than iterate over each caracter and check), it could be a little faster if you replace .sort.pop for .max, I'm still not sure how regex does it, because in order to find all chunks starting with 9 and 4 more digits it still needs to iterate over all the array, so Im not sure why my solution is slower, maybe because the regex is executed in a binary library rather than interpreted like ruby ?

  • Default User Avatar

    I really appreciated the sense of humor in this kata! It made it a lot of fun. But it would probably be a good idea to rename the #each test, because

    #each:
    should execute the block for each item in the bag. why are you messing with this method? work on #every? instead.

    is very confusing, and seems to imply that we cannot use the #each method in the kata. So this kata could use some revision for clarity. Other than that I liked it though.

  • Custom User Avatar

    Given that each and count have already been implemented, you shouldn't need to fully define the Bag class or its initialize method. These should already exist. Your implementation should focus strictly on every? and any further helper methods you need to create for that to work.

  • Default User Avatar

    Thank you for your response Josh. I think you are on to something and I suspect it has to do with the way I'm initializing my Bag class. I currently have this, which sets the array of arguments to the @items instance variable:

    def initialize(*args)
    @items = args
    end

    If I new up a bag, and I call bag.count or bag.each do ... I get the undefined method errors. However, if I do bag.items.count or bag.items.each, those methods work. I guess my question is, do I need to figure out a way to have count and each called on the instance of the class itself? Thanks!

  • Custom User Avatar

    The message "should execute the block for each item in the bag. why are you messing with this method? work on #every? instead" isn't indicative of an error. It's the name of that particular test, for whatever reason.

    The NoMethodErrors suggest that you are somehow passing a nil into the tests. The tests only call each on a bag object and this test passes with the default implementation, so a change you've made seems to have broken each for the Bag class.

  • Loading more items...