使用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

posted @ 2022-09-04 15:14  学习让我充实  阅读(14)  评论(0)    收藏  举报