You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A Harshad number (also known as a Niven number) is an integer that is divisible by the sum of its digits.
Harshad numbers are sometimes called “happy numbers” in recreational mathematics, because they have a simple, satisfying property: their digit sum divides them evenly. They are widely studied in number theory and often appear in math puzzles, programming challenges, and teaching exercises.
Examples
18 is a Harshad number because 1 + 8 = 9 and 18 % 9 === 0.
Hi! I noticed that the previous PR (#1801) was closed without merging. I’d love to take up this issue and implement the Harshad number checker for Hacktoberfest 2025. Could you please assign it to me?
I have worked on the Harshad number checker and created a pull request with the implementation and tests. Please consider my contribution for this issue.
function isHarshad(num) {
if (num <= 0) return false; // Harshad numbers are typically positive integers
// Convert number to string to iterate over digits, then sum them
const sumOfDigits = String(num)
.split('')
.reduce((sum, digit) => sum + parseInt(digit, 10), 0);
// Check divisibility
return num % sumOfDigits === 0;
Activity
[-][FEATURE]:[/-][+][FEATURE]: Add Harshad numbers[/+]Randomlyclueless commentedon Oct 25, 2025
Hi! I noticed that the previous PR (#1801) was closed without merging. I’d love to take up this issue and implement the Harshad number checker for Hacktoberfest 2025. Could you please assign it to me?
feat: add Harshad number algorithm and tests (fixes: TheAlgorithms#1802)
Randomlyclueless commentedon Oct 26, 2025
I have worked on the Harshad number checker and created a pull request with the implementation and tests. Please consider my contribution for this issue.
sharaddh commentedon Jun 5, 2026
function isHarshad(num) {
if (num <= 0) return false; // Harshad numbers are typically positive integers
}
// Test cases
console.log(isHarshad(18)); // true
console.log(isHarshad(19)); // false
console.log(isHarshad(1)); // true
console.log(isHarshad(10)); // true
console.log(isHarshad(12)); // true (1+2=3, 12/3=4)