1function diamond(val) {
2 let y,
3 w,
4 shape = '';
5
6 for (y = 0; y < val * 2 - 1; y++) {
7 w = y < val ? y : val * 2 - y - 2;
8 shape += Array(val - w).join(' ') + Array(w + 1).join('* ') + '*\n';
9 }
10 console.log(shape);
11}
12
13diamond(4);