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.
ok! WTF is this?
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.
This comment is hidden because it contains spoiler information about the solution
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.
This comment is hidden because it contains spoiler information about the solution
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.
This comment is hidden because it contains spoiler information about the solution
well done xD
figured out, ty for everyone
thank you
That's because you're using arrays, and some numbers in tests go up to trillions, so you run out of space for all elements. Try to think of another approach entirely.
Now I have got a memory error :(
Just imagine what you would do if this were asked in a maths exam... hope that helps.
You can also paste your code directly into the discourse usging three back ticks(`):
See here for more.
How could I figur out another approach if I have recently started learning?
It's not about speeding up code per say; it's about finding an approach that works just as fast for small numbers as big ones.
Also have a read below.
Loading more items...