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.
No random tests.
No sample tests.
.
@Wei-LiangChew I'm a little late but then the while loop will iterate over with n - 1 = 8 (and so on)
But what if the largest 5-digit number in
digits
doesn't start with 9?Hey Ricardo! Yeah I thought it was you. I just started codewars :) Thanks man. Hope you're doing good as well!
Hey Freddy, what's up bro? This is Ricardo, from Ayu!
Hope you're well
I just got it, thanks!
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.
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!
Nice one-liner. The Array allocated by
split('')
orchars
gives this algorithmO(n)
space complexity, it's possible to solve this withO(1)
space complexity. All voted on solutions share this problem.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 ?
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.
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.
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!
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...