Last active
July 13, 2017 16:55
-
-
Save cmehrabian/3cd0c7425e1127716aca8527234b5331 to your computer and use it in GitHub Desktop.
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
// Given numRows, generate the first numRows of Pascal's triangle. | |
// For example, given numRows = 5, | |
var generate = function(numRows) { | |
var pascalsTriangle = [ [1] ]; | |
for (var i = 0; i < numRows - 1; i++) { | |
var row = [1]; | |
for (var j = 1; j < pascalsTriangle[i].length; j++) { | |
row[j] = pascalsTriangle[i][j] + pascalsTriangle[i][j-1]; | |
} | |
row.push(1); | |
pascalsTriangle.push(row); | |
} | |
return pascalsTriangle; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment