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

๋ฌธ์ œ ์„ค๋ช…
์–‘์˜ ์ •์ˆ˜ x๊ฐ€ ํ•˜์ƒค๋“œ ์ˆ˜์ด๋ ค๋ฉด x์˜ ์ž๋ฆฟ์ˆ˜์˜ ํ•ฉ์œผ๋กœ x๊ฐ€ ๋‚˜๋ˆ„์–ด์ ธ์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด 18์˜ ์ž๋ฆฟ์ˆ˜ ํ•ฉ์€ 1+8=9์ด๊ณ , 18์€ 9๋กœ ๋‚˜๋ˆ„์–ด ๋–จ์–ด์ง€๋ฏ€๋กœ 18์€ ํ•˜์ƒค๋“œ ์ˆ˜์ž…๋‹ˆ๋‹ค. ์ž์—ฐ์ˆ˜ x๋ฅผ ์ž…๋ ฅ๋ฐ›์•„ x๊ฐ€ ํ•˜์ƒค๋“œ ์ˆ˜์ธ์ง€ ์•„๋‹Œ์ง€ ๊ฒ€์‚ฌํ•˜๋Š” ํ•จ์ˆ˜, solution์„ ์™„์„ฑํ•ด์ฃผ์„ธ์š”.

์ œํ•œ ์กฐ๊ฑด
x๋Š” 1 ์ด์ƒ, 10000 ์ดํ•˜์ธ ์ •์ˆ˜์ž…๋‹ˆ๋‹ค.
*/

const solution = (x) => {
  // ์ •๋‹ต ๋ฆฌํ„ดํ•  ๋ณ€์ˆ˜
  let answer = true;
  // ๊ฐ’ ์ €์žฅ ์œ„ํ•œ ๋ณ€์ˆ˜
  let saving = 0;
  // ์ธ์ž๋กœ ๋„˜์–ด์˜จ ์ˆซ์ž๋ฅผ ๋ฌธ์ž์—ดํ™” ์‹œ์ผœ์„œ ์Šคํ”Œ๋ฆฟ ๋ฉ”์„œ๋“œ๋กœ ์ชผ๊ฐฌ
  const strX = String(x).split('');

  // for๋ฌธ ์Šคํƒ€๋šœ. strX์˜ ๊ธธ์ด๋งŒํผ.
  for (let i = 0; i < strX.length; i++) {
    // ๋Œ๋ฉฐ ์ถ”์ถœํ•œ ๊ฐ ์ธ๋ฑ์Šค ๊ฐ’์„ ์ •์ˆ˜ํ™” ์‹œ์ผœ์„œ saving ๊ฐ’์— ๋”ํ•จ
    saving += Number(strX[i]);
  }
  // ์‚ผํ•ญ์—ฐ์‚ฐ์ž๋ฅผ ์ด์šฉํ•ด ์ธ์ž๊ฐ’์ด saving ๊ฐ’์œผ๋กœ ๋‚˜๋‰˜๋ฉด true ๋ฐ˜ํ™˜. ์•„๋‹ˆ๋ฉด false ๋ฐ˜ํ™˜. answer์— ํ• ๋‹นํ•ด ๋ฆฌํ„ด
  answer = x % saving === 0 ? true : false;
  return answer;
};

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