打印杨辉三角 --JS

var arr = new Array();

for(var i = 0 ;i < 6 ; i++){
if(i == 0){arr.push(1);}
else if(i == 1){arr = new Array();arr.push(1);arr.push(1);}
else{
var arr2 = new Array();
arr2.push(1);
for(var j = 0;j<arr.length - 1; j++){arr2.push(arr[j] + arr[j+1]);}
arr2.push(1);

arr = new Array();
arr = arr2;
}

console.log(arr.join(" "));
}

    原文作者:杨辉三角问题
    原文地址: https://blog.csdn.net/lan_liang/article/details/35637655
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞