๊ด€๋ฆฌ ๋ฉ”๋‰ด

Daehyunii's Dev-blog

์žฌ๊ท€ํ•จ์ˆ˜ ๋ณธ๋ฌธ

๋ฌธ์ œ(์ถœ์ฒ˜ : ์ธํ”„๋Ÿฐ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œํ’€์ด ๊ฐ•์˜, ์ •๋ณด์˜ฌ๋ฆผํ”ผ์•„๋“œ)

 

์ž์—ฐ์ˆ˜ N์ด ์ž…๋ ฅ๋˜๋ฉด ์žฌ๊ท€ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•˜์—ฌ 1๋ถ€ํ„ฐ N๊นŒ์ง€๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์„ธ์š”.

โ–ฃ ์ž…๋ ฅ์„ค๋ช…
์ฒซ ๋ฒˆ์งธ ์ค„์€ ์ •์ˆ˜ N(3<=N<=10)์ด ์ž…๋ ฅ๋œ๋‹ค.

โ–ฃ ์ถœ๋ ฅ์„ค๋ช…
์ฒซ์งธ ์ค„์— ์ถœ๋ ฅํ•œ๋‹ค.

 

โ–ฃ ์ž…๋ ฅ์˜ˆ์ œ 1

3

 

โ–ฃ ์ถœ๋ ฅ์˜ˆ์ œ 1

123

 

Tip

 

๋ฌธ์ œํ’€์ด

//๋‚ด๊ฐ€ ์ž‘์„ฑํ•œ ๋‹ต
function recursive(num){
    let answer = [];
    function solution(num){
        answer.unshift(num);
        if(num === 1) return;
        solution(num-1);
        return;
    }
    solution(num);
    return answer;
}

console.log(recursive(7));