Created
June 3, 2020 15:12
-
-
Save JoeCortopassi/64d8226329d0bb1fab1498f0e6789730 to your computer and use it in GitHub Desktop.
pascal's triangle
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 pascalRow(row) { | |
let prev = []; | |
let curr = []; | |
for (let i = 1; i <= row; i++) { | |
prev = curr; | |
curr = []; | |
if (prev.length === 0) { | |
curr = [1]; | |
continue; | |
} | |
for (let j=0; j<= prev.length; j++) { | |
val1 = prev[j-1] || 0; | |
val2 = prev[j] || 0; | |
curr.push(val1+val2); | |
} | |
} | |
return curr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment