[프로그래머스 | 자바스크립트] 자릿수 더하기
프로그래머스(Javascript)/Level 0
2023. 2. 5. 17:56
솔루션 const solution = (n) => { const answer = [...("" + n)].map((v) => +v).reduce((x, y) => x + y, 0); console.log(answer); return answer; }; 솔루션 const solution2 = (n) => { const answer = n .toString() .split("") .reduce((x, y) => x + Number(y), 0); console.log(answer); return answer; };