Guest User

Untitled

a guest
Jun 23rd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. var generate = function(numRows) {
  2. var previousLine = []; //array to hold each line of the triangle
  3. var overallArr = []; //final array that has all the lines of the triangle in it
  4. if(overallArr === undefined){ //if the final array is undefined
  5. previousLine.push(1); //make the first nested array equal to one to start the triangle
  6. overallArr.push(previousLine); //put the first line of triangle into the overall array
  7. numRows--; //decrement numRows left
  8. }
  9. if(numRows === 0){ //if we run out of number of rows
  10. return overAllArr; //return overallArr/triangle
  11. }
  12. var add = function (rowNumber, previousLine)
  13. if(n > 0){
  14. for(var i = 0; i < previousLine.length < i++){ //loop through previous line
  15. //add the two numbers above (same index + index - 1)
  16. //push sum into previousLine array
  17. //once gone through the previousLine array loop
  18. //push this previousline to the outcome array
  19. }
  20. }
  21. };
Add Comment
Please, Sign In to add comment