- 迴圈輸出
const print = (n) => {
for (let i = 1; i <= n; i++) {
console.log(i);
}
}
複製程式碼
- 遞迴輸出
const print = (n) => {
if (n) {
print(n - 1);
console.log(n);
}
}
複製程式碼
const print = (n) => {
for (let i = 1; i <= n; i++) {
console.log(i);
}
}
複製程式碼
const print = (n) => {
if (n) {
print(n - 1);
console.log(n);
}
}
複製程式碼