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.
in that case in order to passe the tests we shall do to int conversion, will it still be the best practice for this exercice? I used " function summation($n) : int "
Use spoiler flag next time, please.
This comment is hidden because it contains spoiler information about the solution
That's great. But to better protect against overflow with very big $n, i like to write it as "$n/2 * ($n+1)", this way $n will never multiply with $n+1 before the division.
This is the best practice
I'd have liked to use ternary operators on this one, but seemed more complex than usual. Y'know, replacing if and else, considering the 0 values weren't adding up to the final result.
i agree it will re execute the count in each iteration, but maybe he leave it like that to save 1 line of code at the cost of little eficiency.
It doesn't count it, it adds it, and adding 0 is neutral, so...
This solution counts 0 as negative, and 0 is neither positive nor negative.
This comment is hidden because it contains spoiler information about the solution
Why does this work?
I loved this solution!
another note: it is common practice in go to put the
if present
check all on one line.you can look at my solution for a full example
This comment is hidden because it contains spoiler information about the solution
This is not the best practice, because it always runs O(n). Even if the first two chars in the string are equal, it would iterate on all other chars.
Loading more items...