以下是 javascript 中的一些數字模式,這些模式在面試問題中最常被問到。
function printNum(){ for(let i=1; i<=4; i++){ let finalOutput = ''; for(let j=1; j<=i; j++){ finalOutput += i } console.log(finalOutput) } } printNum() output 1 1 2 1 2 3 1 2 3 4
function printNum(){ for(let i=1; i<=4; i++){ let finalOutput = ''; for(let j=1; j<=i; j++){ finalOutput += j } console.log(finalOutput) } } printNum() output 1 1 2 1 2 3 1 2 3 4
function printNum(){ for(let i=1; i<=4; i++){ let finalOutput = ''; for (let k=1; k<=4-i;k++){ finalOutput += " " } for(let j=1; j<=i; j++){ finalOutput += j } console.log(finalOutput) } } printNum() output 1 1 2 1 2 3 1 2 3 4
function printNum(){ for(let i=1; i<=4; i++){ let finalOutput = ''; for (let k=1; k<=4-i;k++){ finalOutput += " " } for(let j=1; j<=i; j++){ finalOutput += i } console.log(finalOutput) } } printNum() output 1 1 2 1 2 3 1 2 3 4
function printNum(){ for(let i=1; i<=4; i++){ let finalOutput = ''; for (let k=1; k<=4-i;k++){ finalOutput += " " } for(let j=1; j<=i; j++){ finalOutput += j + " " } console.log(finalOutput) } } printNum() output 1 1 2 1 2 3 1 2 3 4
function printNum(){ for(let i=1; i<=4; i++){ let finalOutput = ''; for (let k=1; k<=4-i;k++){ finalOutput += " " } for(let j=1; j<=i; j++){ finalOutput += i + " " } console.log(finalOutput) } } printNum() output 1 2 2 3 3 3 4 4 4 4
以上是JavaScript 中的數字模式的詳細內容。更多資訊請關注PHP中文網其他相關文章!