complicated pascal triangle using JavaScript
You are not properly calculating the pascal triangle. Here is my solution, in this code I take advantage of the function .splice() to modify the content of every row. You know that the outter elements of each row are 1s and in between you make the calculations of the sum of the top "root elements", and just like that you get the Pascal's Triangle.



function pascalTriangle(level) {
  let matrix = [[1]];

  for (let row = 1; row &lt; level; row++) {
    matrix.push([1, 1]);
    for (let col = 1; col &lt; row; col++) {
      matrix[row].splice(col, 0, matrix[row - 1][col - 1] + matrix[row - 1][col]);
    }
  }

  return matrix;
}

console.log(pascalTriangle(7));




┌─────────┬───┬───┬────┬────┬────┬───┬───┐
│ (index) │ 0 │ 1 │ 2  │ 3  │ 4  │ 5 │ 6 │
├─────────┼───┼───┼────┼────┼────┼───┼───┤
│    0    │ 1 │   │    │    │    │   │   │
│    1    │ 1 │ 1 │    │    │    │   │   │
│    2    │ 1 │ 2 │ 1  │    │    │   │   │
│    3    │ 1 │ 3 │ 3  │ 1  │    │   │   │
│    4    │ 1 │ 4 │ 6  │ 4  │ 1  │   │   │
│    5    │ 1 │ 5 │ 10 │ 10 │ 5  │ 1 │   │
│    6    │ 1 │ 6 │ 15 │ 20 │ 15 │ 6 │ 1 │
└─────────┴───┴───┴────┴────┴────┴───┴───┘