📅  最后修改于: 2022-03-11 15:03:34.458000             🧑  作者: Mango
function diamond(val) {
let y,
w,
shape = '';
for (y = 0; y < val * 2 - 1; y++) {
w = y < val ? y : val * 2 - y - 2;
shape += Array(val - w).join(' ') + Array(w + 1).join('* ') + '*\n';
}
console.log(shape);
}
diamond(4);