Ad
  • Default User Avatar
    1. Yes, slice is retruning just [2,3]. But the thing is the reduce methode dosen't work on that array. In this example the reduce method uses the original arr array. The return value from slice would be the fourth argument in the reduce methode (acc,curr,index,array). Because array has only two elements reduce is called only two times. Thats why it works.

    2. From 1) follows that arr.length is 4 for you example and index max value is 1 because it's the index auf the array that was returned from the slice method. So it can't be NaN.

  • Default User Avatar

    You have all info in your comment, and if you experiment on the regex101, you will see how group work too
    i just succeed the kata thanks to what you said.
    i guess you probably need to mark it as spoiler for futur people reading it.

  • Default User Avatar

    you can search the website regex101 if you want to know more about regex and try it. Dont forget to select ECMAjs on the left.

  • Custom User Avatar

    You can check the input by printing it. Also consider reading this section: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution#print-input

  • Custom User Avatar

    As said, the tests are random so (say) the third test of this run could be different from the third test of the next run. Because the tests are different for each attempt, the number of failures can change.

  • Custom User Avatar

    What language version are you trying to solve?

    The fact that amount of failed tests varies from attempt to attempt is somewhat expected here, because on Codewars it's desired practice to create a set of random tests for kata, and amount of failures depends on randomized inputs. But the fact that your solution consistently fails probably means it's not correct.

  • Custom User Avatar

    Is the old solution considered brute force?

    Yep, or at least very close to it, compared to faster solutions.

  • Custom User Avatar

    I understand - I probably used the wrong words there. Why not get a pen and paper, draw a map of the street, have a look at what happens at the edges and in the middle, and try to develop your intuition. It'll be worth it ;)

  • Custom User Avatar

    You can't afford any loops ;-)

  • Custom User Avatar

    Hello,
    I'm afraid you are timing out because there are 1995 random tests in js. A brute fore approach won't work. Try to have a think about how to speed up your code... ;)

  • Custom User Avatar

    It has some non-zero chance to pass, and since random tests for this kata are somewhat poor, this solution could finally return correct answer after sufficient amount of retries.

    I am going to raise an issue about improvement for tests.