Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @param {number} numRows
- * @return {number[][]}
- */
- var generate = function(numRows) {
- var oldRow = [];
- var newRow = [];
- var output = [[1]];
- function recurseFunc(previousRow, rowCount) {
- rowCount--;
- newRow = [1];
- if (rowCount === 0) {
- return output;
- } else {
- // console.log('old: ' + oldRow);
- for (let i = 0; i < oldRow.length - 1; i++) {
- newRow.push(oldRow[i] + oldRow[i+1])
- }
- newRow.push(1);
- // console.log('new: ' + newRow);
- oldRow = newRow;
- output.push(newRow);
- recurseFunc(oldRow, rowCount);
- }
- }
- recurseFunc(oldRow, numRows)
- return output;
- };
Add Comment
Please, Sign In to add comment