• (+) operator doing that job
    eg:"WUBWUBWUBWUB".replace(/(WUB)/g) is equal to " " so in this case we get four empty spaces. because it replace every WUB into empty string tha't why we are using + symbol it means it check minimum one 'WUB' matches.
    eg1:"WUB".replace(/(WUB)+/g) is equal to " ",
    eg2:"WUBWUB".replace(/(WUB)+/g) is equal to " ",
    eg3:"WUBWUBWUBWUB".replace(/(WUB)+/g) is equal to " ".in this case there are fout 'WUB' substrings are here so it replace that string into one empty string

  • Got False for

    s = codewars
    part1 = code
    part2 = code
    

    But it is not passing for me. What's going on?

  • @Erhytr how did you figure that out?

  • How does the instances have access to the counter variable? It's not passed as a method (e.g this.counter), it's not passed as a prototype either (e.g Counter.prototype.counter).

    So how? Closure? That would make sense if we call it directly on the Counter function constructor, not its instances.

  • Thanks for your code.

    If you want to see the test cases, you can do that after finishing or forfeiting the kata. :-)

    I tried out your code and I couldn't recreated the problems with the test cases.

    That being said, your code does not completely solve the task. As a hint, try merging "ab" and "bc" to "abcb". It should work.

    (Also, as a side note, if you want to use Java in a bigger context, the convention is that local variables start with a lower-case letter, e.g. mergeWord. It doesn't make any technical difference, so if you're just doing it for fun, you can disregard this. :-) )

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

  • The description of the test case is correct, but the actual call to StringMerger.isMerge is wrong.

    This is a randomly generated test case and I find it difficult to see how it may generate that. The actual code for this particular test case looks like this:

    assertTrue("'Can we merge it? Yes, we can!' is a merge of '" +
                     parts[0] + "' and '" + parts[1] + "'",
                     StringMerger.isMerge("Can we merge it? Yes, we can!", parts[0], parts[1]))
    

    Could it be that you are printing the wrong variables?

    Please try again and see if something went wrong for that test run. Otherwise I would appreciate if you could share you code with me so I could try to reproduce this problem.

  • assertTrue("'Can we merge it? Yes, we can!' is a merge of 'an e mrgite, we a!' and 'Cwee ? Yscn'", StringMerger.isMerge("'Can we merge it? Yes, we can!' ", "'an e mrgite, we a!'", "'CnwemrgtYescn' "));

    This test case is wrong....... as the order is messed up and the string length doesn't queal the length of part1+part2 making it impossible to merge correctly.

  • Thanks for this, I had the same question.

  • Thanks for this, I had the same question.

  • How does this code remove the multiple spaces? I can only understand how it replaces the WUBs with a space each time, not how it accounts for the potential multiple spaces

  • Abbe, please use spoiler flag next time.

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

  • i understand the math.min part but can someone explain why "...args"? why not just "args"

  • ^ CORRECTIONS AND TO BE MORE SPECIFIC:
    The + means to match whatever is infront of it 1 or more times**

    Then you have the astric * (which is not included but important to differentiate from the plus) it matches whatever is infront of it from 0 or more times.

    And finally g the global tells regex to not stop after the first match but continue and look for more matches

  • Loading more items...