无聊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);

 

posted on 2014-07-09 09:41  坚壳  阅读(833)  评论(0编辑  收藏  举报