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.
The same I used. I think that, considering the four basic arithmetical operations, on the 'else' it works great. However, it's always good to be as specific as possible when indicating the operations. What in the case of 'modulo' (%)?
One-line solutions are always cool.
This one is practical, sure, however I find it quite long.
I had thought a workaround regarding turning the array into a string, apply the reverse on it and then turn it back into an array.
But since this exists on PHP, no real need. Just for the fun of tinkering around with it.
Just my solution. Although, in my case, I'd prefer to keep the curly braces to ease readability of the code.
This comment is hidden because it contains spoiler information about the solution
static typing is what you are looking for
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.
Hey everyone!
I hope this is not a dumb question, but I'm interested in knowing the name of this syntax or trend for writing functions:
function square_sum($numbers) : int {
// Write your code here...
}
Does this mean that the return parameter must be an integer, no matter what the inner process could be?
I have my ways around PHP, but I usually struggle identifying titles of topics that explain this kind of thing.
Thanks!
Nice. Compact solution.
Simple and straight to the point. I did it like this too.
The same I used. I think that, considering the four basic arithmetical operations, on the 'else' it works great. However, it's always good to be as specific as possible when indicating the operations. What in the case of 'modulo' (%)?
Although Ruby does allow it that way, I honestly prefer to enclose the parameters the function uses between parentheses. Mho.