/*
https://school.programmers.co.kr/learn/courses/30/lessons/12928

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

์ œํ•œ ์‚ฌํ•ญ
n์€ 0 ์ด์ƒ 3000์ดํ•˜์ธ ์ •์ˆ˜์ž…๋‹ˆ๋‹ค.
*/

const solution = (n) => {
  let answer = 0;
  for (let i = 0; i <= n; i++) {
    // for๋ฌธ์„ ๋งค๊ฐœ๋ณ€์ˆ˜ n์˜ ๊ฐ’๊ณผ ๊ฐ™์•„์งˆ๋•Œ๊นŒ์ง€ ๋Œ๋ฆฐ ๋’ค
    if (n % i === 0) {
      // n๊ฐ’์ด ์ธ๋ฑ์Šค ๊ฐ’๊ณผ ๋‚˜๋ˆ ์ง„๋‹ค๋ฉด ๊ทธ ์ธ๋ฑ์Šค ๊ฐ’์€ ํ•ด๋‹น ๋งค๊ฐœ๋ณ€์ˆ˜์˜ ์•ฝ์ˆ˜.
      answer += i; // answer ๊ฐ’์— ์•ฝ์ˆ˜๋ฅผ ๋ˆ„์ ํ•ด์„œ ๋”ํ•จ
    }
  }
  return answer;
};

console.log(solution(12));
console.log(solution(5));
๋ณต์‚ฌํ–ˆ์Šต๋‹ˆ๋‹ค!