首页 > 代码库 > 无聊js画了个菱形

无聊js画了个菱形

function repeat(str, count) {    return count < 0 ? ‘‘ : (new Array(count)).join(str);}function diamond(sign, size) {    var d,        s = ‘‘    for (var i = 0; i < size*2; i++) {        d = Math.abs(size-i-1);        console.log(d+1, 2*(size-d));        s += repeat(‘&nbsp;‘, d+1) + repeat(sign, 2*(size-d)) + repeat(‘&nbsp;‘, d+1) + ‘<br/>‘;    };    document.write(s);}diamond(‘A‘, 5);