0
I want to make JavaScript number pyramid
I want to make like this 1 232 34543 4567654 This is my code var n = 8; for (var i = 0; i < n; i++) { var str = ''; for (var j = 1; j < n-i; j++) { str = str + ''; } for (var k = 1; k <= (2*i+1); k++) { str = str + '*'; } //for (var l = 1; l < n; l--) { // str = str + 'k'; // } console.log(str); } i try it for 3days and I cannot pass it. Thank you very much for help.
1 Answer
+ 1
did you try to get:
var dig = (v,i) => (v+i)%10,
rev = s => [...s].reverse().join(''),
row = (v,i) => ' '.repeat(n- ++i)+(v = Array(i).fill(i).map(dig).join(''))+rev(v.slice(0,-1)),
shape = n => Array(n).fill().map(row).join('\n');
document.write('<pre>'+shape(8)+'</pre>');