Advertisement
that1paster

halpplox2

Aug 24th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function getPascalsTriangle(n) {
  2.     var arr = {};
  3.     for(var row = 0; row < n; row++) {
  4.         arr[row] = [];
  5.         for(var col = 0; col < row+1; col++) {
  6.             if(col === 0 || col === row) {
  7.                 arr[row][col] = 1;
  8.             } else {
  9.                 arr[row][col] = arr[row-1][col-1] + arr[row-1][col];
  10.             }        
  11.         }      
  12.     }  
  13.     return arr[n - 1];
  14. }
  15. console.log(getPascalsTriangle(5))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement