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.
In Python and Ruby you should only set the regex var value, you can't control what the tests do. Not a kata issue.
Marked as resolved.
jsfiddle only calls your function once. CW calls your function multiple times. That's the difference.
Think about what happens when your function is called the second time ;-)
Edit: Even better, don't just put 1 function call on your jsfiddle. Put multiple of them, in the exact way the tests in CW are done ;-)
Better than me explaining it, why don't you try calling your function several times and checking the result?
Hm - specifically, that global variable would give me a different outcome between jsfiddle and codewars?
if you don't mind, could you explain how that would be the case?
Actually - nevermind - I have a feeling I am not able to explain exactly what I am noticing - and this isn't going to be helpful in the end. I really appreciate the input and help. Thank you.
Already told you before, the global var (count) keeps its value between tests, giving you wrong values after the first call.
Thank you so much - always helpful. I guess, though -- if you don't mind -- what I was wondering about is that I got such different outcomes from jsfiddle vs codewars.
I was surprised by that and wondered why.
Variable "b" inside "reducer" function must be integer, so you can use a * parseInt(b),
you can delete for loop, keep if-else statement.
Also "reduce" need initial value (1 in your case).
Hint: you should use "return" on two places (becouse of recursion).
Don't use global vars, they keep their values between tests.
Your function doesn't return.
This comment is hidden because it contains spoiler information about the solution
I am certain my code is too complicated, so forgive me. I only started this journey a few weeks ago. I am learning.
Would it be okay to ask for suggestions on debugging? I have thought of every single edge case I can -- and I still average around 20 failed tests each time.
Again, I get one thing I am doing rather clunkily at this point is creating bloated code. For me, in these early stages of learning, separating out each step like this is the best I can do and actually helps me think through the problem...
So, that said -- I apologize for that.
The question I have is this:
Here is my code so far:
(I recently added in some if clauses to try to test to see if those elements were an issue...so that is why they are there...)
function tripledouble(num1, num2) {
var re = /^\d*(\d)\1{2}\d*$/g;
var myArray = num1.toString().split(re);
if (myArray === null) {
return 0;
} else {
var myStr = myArray.toString();
var res = myStr.replace(/[, ]+/g, " ").trim();
var res2 = res + res;
var re2 = new RegExp(res2, "gi");
var MyArray2 = num2.toString().match(re2);
if (MyArray2 === undefined) {
return 0;
}
if (MyArray2 === null) {
return 0;
}
if (MyArray2.length >= 0) {
return 1;
}
else {
return 0;
}
}
}
var num1 = 799900990;
var num2 = 990010000;
alert(tripledouble(num1, num2));
Oh I always do that. Thank you again. I only started learning a few weeks ago.
No problem. Now after you've done it your way, I suggest you see how other people solved it and learn different ways of doing it.
This comment is hidden because it contains spoiler information about the solution
Debug your code for that case then. If you still have the same problem, you're not using reduce the right way.
Loading more items...