Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var generate = function(numRows) {
- var result = [];
- for (var i = 0; i < numRows; i++) {
- var row = [];
- for(var j = 0; j < i + 1; j++) {
- var val = 1;
- if(j !== 0 && j !== i){
- val = result[i - 1][j - 1] + result[i - 1][j];
- }
- row.push(val);
- }
- result.push(row);
- }
- return result;
- };
Add Comment
Please, Sign In to add comment