Created
March 14, 2019 14:05
-
-
Save basicssm/518e11e264c8e32400f65119e612ec7d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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