Skip to content

Instantly share code, notes, and snippets.

@vladimir-ivanov
Last active November 13, 2015 20:51
Show Gist options
  • Save vladimir-ivanov/2b0b0dd2e76bd58c4ceb to your computer and use it in GitHub Desktop.
Save vladimir-ivanov/2b0b0dd2e76bd58c4ceb to your computer and use it in GitHub Desktop.
//could also be a non recursive function etc
function factorial(n) {
return (n < 2) ? 1 : factorial(n-1) * n;
}
function getElementAtPosition(n, k) {
return factorial(n) / (factorial(k) / factorial(n-k));
}
function pascalRow(n) {
var row = [];
for(var i=0; i<=n; i++) {
row.push(getElementAtPosition(n, i));
}
return row;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment