You are viewing a single comment's thread. Return to all comments →
I think more general and better solution is to declare maxSum outside of loop and then after calculating sum add:
// on first iteration save sum to compare
if (y === 0 && x === 0) maxSum = sum;
This sets maxSum to first calculated sum, whatever it is.