We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9fa5a04 commit 548fe75Copy full SHA for 548fe75
1 file changed
Maths/IsHarshad.js
@@ -3,22 +3,22 @@
3
* A Harshad number (or Niven number) is a positive integer that is divisible by the sum of its own digits.
4
*
5
* The function checks if a number is a Harshad (Niven) number.
6
- * @param {any} n - The number to check
+ * @param {any} val - The number to check
7
* @returns {boolean} - true if Harshad, false otherwise
8
* @example isHarshad(2025) // true
9
*/
10
-export const isHarshad = (n) => {
11
- const num = Number(n)
+export const isHarshad = (val) => {
+ const num = Number(val)
12
13
if (num <= 0 || !Number.isInteger(num)) return false
14
15
let sum = 0,
16
- temp = n
+ temp = num
17
18
while (temp > 0) {
19
sum += temp % 10
20
temp = Math.floor(temp / 10)
21
}
22
23
- return n % sum === 0
+ return num % sum === 0
24
0 commit comments