Skip to content

Instantly share code, notes, and snippets.

@edalorzo
Created December 6, 2013 06:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edalorzo/7819287 to your computer and use it in GitHub Desktop.
Save edalorzo/7819287 to your computer and use it in GitHub Desktop.
Pascal Triangle
function pascal(depth){
var value = function(col,row){ return (col===1 || row===1 || col===row) ? 1 : value(col-1, row-1) + value(col, row-1); }
return Array.apply(null, {length: depth})
.map(function(u,row,self){ return Array.apply(null,{length:row+1}).map(function(u,col,self){ return value(col+1,row+1)}); });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment