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.
very useful, thank you so much
Nice regex. Tbh, I thought we were going to hard-code a finite state machine of the "binary multiple of 3", but regex is nice too.
The task is to create a regex that can be used to check whether a string is the binary representation of a number divisible by 3, not a function.
This comment is hidden because it contains spoiler information about the solution
The regular expression should not use the
g
flag.Chai uses
re.exec
when it tests a regular expressionre
. This regular expression matches'000'
and itslastIndex
is set to3
(because theg
flag is set). The next test callsre.exec('110')
. The match starts from the newlastIndex
position and it fails.There is something weird indeed with the tests, if you only leave that one in the sample tests, your code passes it. But, your code is not ok, and it returns true for any combination of 0 and 1 with 3 digits.
Test failing even though it is a match when I console.log the test using
multipleOf3Regex.test('110')
My solution is
const multipleOf3Regex = /^[0-1]{3}$/g
This comment is hidden because it contains spoiler information about the solution
kata hint != kata suggestion
Remember about the 6th rule!!!
I spent approximately 2 hours only because I am so stupid I did't notice the 6th rule.
Using global variables is your mistake, and not a kata problem. Code with global variables will work incorrectly everywhere, and not only on Codewars.
ahh I solved it, the kata don't count the global variables so I put it to the function and it works correctly. waste 2 hours to discover that :(
I attempted my code on a compiler with case 'D',3 and it return 37 but when I attempt in the kata it return 30 instead. what's the problem??
ok, this was a pretty good challenge.
I took a while to get it what's going on.
This comment is hidden because it contains spoiler information about the solution
Loading more items...