编辑代码

function printPatternRecursive(row, num) {
  if (row > num) {
    return;
  }
  let output = '';
  for (let i = 1; i <= row; i++) {
    output += num + ' ';
  }
  console.log(output);
  printPatternRecursive(row + 1, num);
}
function printPattern(n) {
  printPatternRecursive(1, n);
}
printPattern(5);  // 调用示例

function printPattern(n) {
  const pattern = new Array(n);

  for (let row = 0; row < n; row++) {
    pattern[row] = new Array(row + 1).fill(row + 1);
    console.log(pattern[row].join(' '));
  }
}

printPattern(5);  // 调用示例