Skip to content

Instantly share code, notes, and snippets.

@basicssm
Created March 14, 2019 14:05
Show Gist options
  • Save basicssm/518e11e264c8e32400f65119e612ec7d to your computer and use it in GitHub Desktop.
Save basicssm/518e11e264c8e32400f65119e612ec7d to your computer and use it in GitHub Desktop.
function rowSumOddNumbers(n) {
let i = 0;
let oddCount = n;
let count = n;
let toSum = [];
while(n !== 0){
oddCount += (n - 1);
n -= 1;
}
while(toSum.length !== oddCount){
if(i%2){
toSum = [...toSum, i];
}
i++;
}
return toSum.slice(-Math.abs(count)).reduce((acc, el) => acc += el);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment