Ad
  • Custom User Avatar
  • Custom User Avatar

    Got it! Thanks for the clarification.

  • Custom User Avatar

    It doesn't says both are valid, it says one digit can belong to two adjacent digit-pairs.

    We define a digit-pair as: Two digits with at least one question mark between them.

    Your task is to check if there are exactly 3 question marks between every digit-pair and their sum equals to 10. If so, return true, otherwise return false.

    For that string your code should return false, as the similar sample test shows.

  • Custom User Avatar

    Note: a digit can belong to two adjacent digit-pairs. For example, in string 1???9??1, 1???9 is a digit-pair, 9??1 is also a digit-pair.

    Could someone explain this to me.
    How does the above represent two valid digit-pairs?
    Or is it a typo?

    Because there are 3 ??? between the 1 and 9
    However there is not three ??? which follow the 9.
    So how can the answer be valid?

    Also looking at the sample tests shows
    Test.assertEquals(sum10("1???x9??1"), false)

    That is what I would expect.

    So is the description meant to read:
    "***Note: a digit can belong to two adjacent digit-pairs.
    For example, in string 1???9???1, 1???9 is a digit-pair, 9???1 is also a digit-pair."

    Thank you

  • Custom User Avatar

    Aha! I understand now. Thank you

  • Custom User Avatar

    I solved the kata in JavaScript, so I am able to see your code. Your code passes the first sample tests, but fails in some of the series

      it("Special cases (splits at start/end and overlapping splits)", function() {
    

    for example

        Test.assertSimilar(splitWithoutLoss("aaaa", "|aa"), 
                           ["aa", "aa"])
    

    I don't think it works fine in VSC either.

  • Custom User Avatar

    Thank you, akar-0

    But as you can see I posted exactly the input so that you can
    see what I am using!
    All I did was change the 'test.assert...' string to 'console.log'
    That's it!
    And ran both programs which displayed the answers straightaway
    As you can see

    I would gladly send you the source code of my solution so that you can see what I mean, if that helps!

  • Custom User Avatar

    FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

    This means you are using too much memory (you are probably building a gigantic array or something like this, or a part of your code keeps pushing value into something and never stops), and it is not a kata issue.

    Advice: your while loop is probably the culprit. You are probably not testing your code with the same input in VSC as here. Please refer to the documentation: https://docs.codewars.com/training/troubleshooting/

  • Custom User Avatar

    Greetings

    I have written two different solutions which both use a loop. No recursion.
    Both run fine in Visual Studio but both crash with memory problems in Codewars

    FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

    I have tried both 'resetting' and changing the Node versions.
    I get the same errors

    How do I proceed?

    This is my output from Visual Code:

    console.log(splitWithoutLoss("hello world!", " |"), ["hello ", "world!"]);
    console.log(splitWithoutLoss("hello world!", "o|rl"), ["hello wo", "rld!"]);
    console.log(splitWithoutLoss("hello world!", "ello| "), ["hello", " world!"]);
    console.log(splitWithoutLoss("hello world!", "hello wo|rld!"), [
    "hello wo",
    "rld!",
    ]);
    console.log(splitWithoutLoss("hello world!", "h|ello world!"), [
    "h",
    "ello world!",
    ]);

    console.log(splitWithoutLoss("hello world! hello world!", " |"), [
    "hello ",
    "world! ",
    "hello ",
    "world!",
    ]);

    console.log(splitWithoutLoss("hello world! hello world!", "o|rl"), [
    "hello wo",
    "rld! hello wo",
    "rld!",
    ]);

    console.log(splitWithoutLoss("hello world! hello world!", "ello| "), [
    "hello",
    " world! hello",
    " world!",
    ]);

    console.log(splitWithoutLoss("hello world! hello world!", "hello wo|rld!"), [
    "hello wo",
    "rld! hello wo",
    "rld!",
    ]);

    console.log(splitWithoutLoss("hello hello hello", " | "), [
    "hello ",
    " hello ",
    " hello",
    ]);

    Which Produced:

    [ 'hello ', 'world!' ] [ 'hello ', 'world!' ]
    [ 'hello wo', 'rld!' ] [ 'hello wo', 'rld!' ]
    [ 'hello', ' world!' ] [ 'hello', ' world!' ]
    [ 'hello wo', 'rld!' ] [ 'hello wo', 'rld!' ]
    [ 'h', 'ello world!' ] [ 'h', 'ello world!' ]

    [ 'hello ', 'world! ', 'hello ', 'world!' ] [ 'hello ', 'world! ', 'hello ', 'world!' ]

    [ 'hello wo', 'rld! hello wo', 'rld!' ] [ 'hello wo', 'rld! hello wo', 'rld!' ]

    [ 'hello', ' world! hello', ' world!' ] [ 'hello', ' world! hello', ' world!' ]

    [ 'hello wo', 'rld! hello wo', 'rld!' ] [ 'hello wo', 'rld! hello wo', 'rld!' ]

    [ 'hello ', ' hello ', ' hello' ] [ 'hello ', ' hello ', ' hello' ]

  • Custom User Avatar

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

  • Custom User Avatar
  • Custom User Avatar

    Good job!
    I also think about using RegExp and match(), but I not so good in it.