Last active
November 13, 2015 20:51
-
-
Save vladimir-ivanov/2b0b0dd2e76bd58c4ceb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
//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