I have this exact problem. Can you or someone give a hint how to resolve it?
For anyone else coming across this: Utilize parentheses. I hope this isn't too spoilery...
Its not recalculating the average on each iteration. In this case, for doesnt has any braces
so is executing the first line only. This solution has "stetic" problems with tabs but is correct.
I have this exact problem. Can you or someone give a hint how to resolve it?
For anyone else coming across this: Utilize parentheses. I hope this isn't too spoilery...
//bad indentation
Hi.
What is the point in creating new variable avg? You could just
return sum / array.length;
Regards
Its not recalculating the average on each iteration. In this case, for doesnt has any braces
so is executing the first line only. This solution has "stetic" problems with tabs but is correct.
The code is misaligned and "for" doesn't have braces. Yes, from first look the solution doesn't seem to be valid.
Is this best practice? This recalculates the average on each iteration but we only need the final average.