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.
you should change class greet() to static method
But isn't the check performed at the start of the expression? Array length will always be greater than or equal to zero. If the value of n is negative then the function returns -1 in this solution.
Edit:
Okay, I'm dumb :D
@vasyl.shevchuk.78
yes you are right. It would be better to test for it. But the Kata description was a bit vague about the possible values ofn
and since that case is never tested so I assumedn >= 0
always.Read about "?" operator in java.
This solution will throw ArrayIndexOutOfBoundsException if n will negative
How did you solve it? I have it working on node, but not in codewars?
a bit easy for 6kyu...unless there is additional constraint.
solved now!