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 used their hashcodes right man?
ivanightingale, what is wrong with that?
oohhh you clever devil. I mapped out the entire alphabet smh lol.
I like the "why break at all if you can return the result straight away?" People should try it out before they say something.
You can get away with putting a return in the middle of a small easy to read function like this. But it is generally better practice to try to limit a method to one return.
It is easier for someone else to understand the method when there is fewer returns from the method. Easier to see where the function can end.
Why can't you return the result straight away using break?
why break at all if you can return the result straight away?
instead of using the 'stop' boolean, you could use the built in command 'break' to break the for loop when the condition is met.
Yes, you can use a break clause in order to stop the loop.
But, in my opinion, breaks and gotos are not a "good practice".
You could also place the return statement after the "missingLetter+=1" (this is the line that you use for find the correct number of the letter).
Another option, you can use booleans. You can declare a boolean found = false; at the beginnig, use it in the loop (for(int i = 0; i < array.length-1 && !found; i++)) and, when you found the letter, write found = true;
So, the next time you return to the loop condition, !found will be false, so yo won't enter again, and you save a lot of time.
I hope was helpful :D
like break after missingLetter = arra[i] + 1; ?
I think using a 'return' clause inside the loop will save unnecessary iterations when we already have the desired output. Boolean conditions are easier to read in my opinion, but tend to have longer run times.
Do you think it's efficient to use a 'return' clause inside a loop?
Would not it be better to use boolean conditions?
You are watching all array's elements, but you only need to see elements until you find the missing one.
If the array had had 1000 elements and the missing one was found in the 1st iteration, you would be doing an extra effort.
Use a boolean or similar :D.