everyutil
Version:
A comprehensive library of lightweight, reusable utility functions for JavaScript and TypeScript, designed to streamline common programming tasks such as string manipulation, array processing, date handling, and more.
15 lines (14 loc) • 502 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isHarshadNumber = void 0;
/**
* Checks if a number is a Harshad number (divisible by the sum of its digits).
* @author @dailker
* @param {number} n - The number to check.
* @returns {boolean} True if Harshad number.
*/
function isHarshadNumber(n) {
const sum = Math.abs(n).toString().split('').reduce((a, b) => a + +b, 0);
return n % sum === 0;
}
exports.isHarshadNumber = isHarshadNumber;