【发布时间】:2017-12-07 01:23:33
【问题描述】:
所以我有一个函数 getNext,它接受一个参数 i。该函数需要递归迭代,直到 i 为 0。但是,在函数中,我需要一组数字从 2 增加。
function getNext(i) {
if(i == 0) return;
console.log('index: ' + i);
console.log( code_here );
i--;
getNext(i);
}
所以 getNext(3) 的输出将是:
index: 3
2
index: 2
3
index: 1
4
有什么想法吗?我正在尝试在不添加额外变量的情况下执行此操作,但我不知道是否可能。
【问题讨论】:
-
I need a set of numbers to increase from 2你能解释更多吗?你可以把预期的输出。 -
@MohamedAbbas 预期的输出低于问题。
-
我做了一些解决方案,如果它不能满足您的需求,请告知。
标签: javascript math recursion iteration