使用yeild* 实现递归算法
function* nTimes(n) { if (n > 0){ yield* nTimes(n-1); yield n-1; } } for(const x of nTimes(4)){ console.log(x); }
输出:0 1 2
function* nTimes(n) { if (n > 0){ yield* nTimes(n-1); yield n-1; } } for(const x of nTimes(4)){ console.log(x); }
输出:0 1 2