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 33 * A Harshad number (or Niven number) is a positive integer that is divisible by the sum of its own digits.
44 *
55 * 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
77 * @returns {boolean } - true if Harshad, false otherwise
88 * @example isHarshad(2025) // true
99 */
10- export const isHarshad = ( n ) => {
11- const num = Number ( n )
10+ export const isHarshad = ( val ) => {
11+ const num = Number ( val )
1212
1313 if ( num <= 0 || ! Number . isInteger ( num ) ) return false
1414
1515 let sum = 0 ,
16- temp = n
16+ temp = num
1717
1818 while ( temp > 0 ) {
1919 sum += temp % 10
2020 temp = Math . floor ( temp / 10 )
2121 }
2222
23- return n % sum === 0
23+ return num % sum === 0
2424}
You can’t perform that action at this time.
0 commit comments