lil.dev
Published on

๐Ÿซ ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค - ์•ฝ์ˆ˜์˜ ํ•ฉ

๊ธ€์“ด์ด

    ๐Ÿ“Œ ๋ชฉ์ฐจ

    • ๐Ÿ‘ ๋งํฌ
    • ๐Ÿ‹ ๋ฌธ์ œ ์„ค๋ช…
    • ๐Ÿ ์ œํ•œ ์กฐ๊ฑด
    • ๐ŸŠ ํ’€์ด
    Welcome

    ๐Ÿ‘ ๋งํฌ

    ์•ฝ์ˆ˜์˜ ํ•ฉ

    ๐Ÿ‹ ๋ฌธ์ œ ์„ค๋ช…

    ์ •์ˆ˜ n์„ ์ž…๋ ฅ๋ฐ›์•„ n์˜ ์•ฝ์ˆ˜๋ฅผ ๋ชจ๋‘ ๋”ํ•œ ๊ฐ’์„ ๋ฆฌํ„ดํ•˜๋Š” ํ•จ์ˆ˜, solution์„ ์™„์„ฑํ•ด์ฃผ์„ธ์š”.

    ๐Ÿ ์ œํ•œ ์กฐ๊ฑด

    n์€ 0 ์ด์ƒ 3000์ดํ•˜์ธ ์ •์ˆ˜์ž…๋‹ˆ๋‹ค.

    ๐ŸŠ ํ’€์ด

    //์•ฝ์ˆ˜ ๊ตฌํ•˜๋Š” ๋ฒ•
    //๋ชจ๋‘ ๋”ํ•˜๋Š” ๊ฑฐ -Reduce
    //https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce
    
    const arrDivisor = [];
    let answer = 0;
    let i = 1;
    
    function solution(n) {
    
        while (i < = n){
            if( n % i === 0){
                arrDivisor.push(i);
            }
            i += 1;
            answer = arrDivisor.reduce((preVal,curVal) => preVal + curVal, 0)
        }
    
        return answer;
    }