File tree Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Original file line number Diff line number Diff line change 3
3
* A Harshad number (or Niven number) is a positive integer that is divisible by the sum of its own digits.
4
4
*
5
5
* The function checks if a number is a Harshad (Niven) number.
6
- * @param {any } n - The number to check
6
+ * @param {any } val - The number to check
7
7
* @returns {boolean } - true if Harshad, false otherwise
8
8
* @example isHarshad(2025) // true
9
9
*/
10
- export const isHarshad = ( n ) => {
11
- const num = Number ( n )
10
+ export const isHarshad = ( val ) => {
11
+ const num = Number ( val )
12
12
13
13
if ( num <= 0 || ! Number . isInteger ( num ) ) return false
14
14
15
15
let sum = 0 ,
16
- temp = n
16
+ temp = num
17
17
18
18
while ( temp > 0 ) {
19
19
sum += temp % 10
20
20
temp = Math . floor ( temp / 10 )
21
21
}
22
22
23
- return n % sum === 0
23
+ return num % sum === 0
24
24
}
You can’t perform that action at this time.
0 commit comments