๋ฐ์ํ
https://school.programmers.co.kr/learn/courses/30/lessons/12931
C++์ค๋ฌ์ด ํ์ด
function solution(n)
{
var answer = 0;
for(let i=0; n>0; i++) {
answer += n%10;
n = parseInt(n /= 10);
}
return answer;
}
๋ฌธ์์ด์ ์ด์ฉํ ํ์ด
function solution(n)
{
var answer = 0;
var stringN = (n+"");
var arrN = stringN.split("");
arrN.forEach((i) => answer += parseInt(i));
return answer;
}
๋ฐ์ํ
'๐ ๋ญ? JS๋ก PS๋ฅผ ํ๋ค๊ณ ?' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค] ๋๋จธ์ง๊ฐ 1์ด ๋๋ ์ ์ฐพ๊ธฐ (0) | 2023.04.03 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค][Javascript / JS] x๋งํผ ๊ฐ๊ฒฉ์ด ์๋ n๊ฐ์ ์ซ์ (0) | 2023.03.31 |
[ํ๋ก๊ทธ๋๋จธ์ค][JS / Javascript] ์ฝ์์ ํฉ (0) | 2023.03.29 |
[ํ๋ก๊ทธ๋๋จธ์ค][JS / Javascript] ํ๊ท ๊ตฌํ๊ธฐ (0) | 2023.03.28 |
[ํ๋ก๊ทธ๋๋จธ์ค][JS / Javascript] ๋ ์์ ๊ณฑ (0) | 2023.03.27 |