Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4060246

Browse files
jaewon1676prove-ability
authored andcommitted
Update 히샤드 수.js
1 parent 0dd72c5 commit 4060246

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

‎level-1/히샤드-수.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,16 @@ function solution(x) {
2222
}
2323
// x가 각 자릿수의 합으로 나누어떨어지는지 여부 반환
2424
return x % sum_of_digits == 0;
25-
}
25+
}
26+
27+
//정답 3 - jaewon1676
28+
function solution(x) {
29+
let sum = 0;
30+
let arr = String(x).split(''); // 숫자를 하나씩 분리한다.
31+
32+
for(var i=0; i<arr.length; i++) {
33+
sum += Number(arr[i]); // 각 숫자를 더해준다.
34+
}
35+
36+
return (x % sum == 0) ? true : false; // 자릿수의 합으로 x가 나누어지면 하샤드 수
37+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /