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.
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.
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.
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.
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.
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
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.
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.
Yep, or at least very close to it, compared to faster solutions.
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 ;)
You can't afford any loops ;-)
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... ;)
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.