Skip to content

Instantly share code, notes, and snippets.

@JoeCortopassi
Created June 3, 2020 15:12
Show Gist options
  • Save JoeCortopassi/64d8226329d0bb1fab1498f0e6789730 to your computer and use it in GitHub Desktop.
Save JoeCortopassi/64d8226329d0bb1fab1498f0e6789730 to your computer and use it in GitHub Desktop.
pascal's triangle
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