Ad
  • Custom User Avatar

    In Python and Ruby you should only set the regex var value, you can't control what the tests do. Not a kata issue.

  • Custom User Avatar

    Marked as resolved.

  • Custom User Avatar

    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 ;-)

  • Custom User Avatar

    Better than me explaining it, why don't you try calling your function several times and checking the result?

  • Custom User Avatar

    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.

  • Custom User Avatar

    Already told you before, the global var (count) keeps its value between tests, giving you wrong values after the first call.

  • Custom User Avatar

    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.

  • Default User Avatar

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

  • Custom User Avatar

    Don't use global vars, they keep their values between tests.
    Your function doesn't return.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    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:

    1. What are the specific steps to take to be able to see the test cases - if this is possible?
    2. What are some good resources for coming up with the edge cases that are stopping me from passing the tests?

    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));

  • Custom User Avatar

    Oh I always do that. Thank you again. I only started learning a few weeks ago.

  • Custom User Avatar

    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.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

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