九九乘法表 js版

随便写写

for(let i = 1;i <= 9;i++) {  
  let m = "";
  for(let j = 1;j <= i;j++) {
    m += `${j}*${i}=${i * j} `
  }
  console.log(m)
}

不过在知乎上看到另一种写法

console.log([...Array(9)].reduce( (m, _, x) => m + [...Array(x + 1)].reduce( (m, _, y) => m += `${y + 1}*${x + 1}=${(x + 1) * (y + 1)} `, "") + "\n", ""));