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.
24 lines (23 loc) • 629 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isPerfectNumber = void 0;
/**
* Checks if a number is a perfect number (equal to sum of its divisors except itself).
* @author @dailker
* @param {number} n - The number.
* @returns {boolean}
*/
function isPerfectNumber(n) {
if (n <= 1)
return false;
let sum = 1;
for (let i = 2; i <= Math.sqrt(n); i++) {
if (n % i === 0) {
sum += i;
if (i !== n / i)
sum += n / i;
}
}
return sum === n;
}
exports.isPerfectNumber = isPerfectNumber;