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.
nice approach
https://docs.oracle.com/javase/8/docs/api/java/util/List.html#toArray-T:A-
Why is 'new String[0]' passed in as parameter to the toArray method. What does it even mean? Thanks in advance.
Because at that point index
i+1
is same as string length.And exception is not thrown by substring unless index is greater than string length
Refer: https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#substring(int)
Can someone explain how when the i gets to the last letter (str.length -1) there is not an out of bounds exception caused by the str.substring(i+1) ?
Compare:
Personally, I find option 1 is more natural way to describe the alogrithm. YMMV.
Is the use of the keyword "continue" better than using brackets in this case?
Thank you, after correctly copied the array the kata showed no errors.
Do a
console.log
ofnumbers
before the return line, you've mutated the input.var arrayCopy = numbers; //Copy the array, just in case
doesn't make a copy, both vars point to the same array. Try looking in the web how to make a swallow copy of an array.Or you could try creating a new array instead, or both ;)
This comment is hidden because it contains spoiler information about the solution
Post your code, mark your post as having spoiler content.
I'm having troubles with this, the random test cannot be passed because it tooks the 2nd and 3rd element from the array, and I didn't changed the original array, here are some samples from the random test
Log
[ 1038, 40, 62, 55, 38 ]
78
Expected: 117, instead got: 78
Log
[ 1000, 27, 32, 25, 40 ]
52
Expected: 72, instead got: 52
Log
[ 1067, 65, 92, 50, 96 ]
115
Expected: 188, instead got: 115
Log
[ 1087, 73, 32, 31, 100 ]
63
Expected: 173, instead got: 63
Log
[ 1044, 72, 22, 19, 21 ]
40
Expected: 94, instead got: 40
Log
[ 1076, 26, 80, 97, 0 ]
26
Expected: 177, instead got: 26