Skip to content

Instantly share code, notes, and snippets.

@diasraphael
Created July 20, 2021 20:49
Show Gist options
  • Save diasraphael/1faa8c0dab6539586832e78beefee5ac to your computer and use it in GitHub Desktop.
Save diasraphael/1faa8c0dab6539586832e78beefee5ac to your computer and use it in GitHub Desktop.
function rowSumOddNumbers(n) {
let startValue = n * (n - 1) + 1;
let sum = 0;
for (let i = 1; i <= n; i++) {
if (i == 1) {
sum = startValue
} else {
startValue = startValue + 2;
sum = sum + startValue;
}
}
return sum;
}
console.log(rowSumOddNumbers(4));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment