UNPKG

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.

22 lines (21 loc) 602 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.factors = void 0; /** * Returns all factors of a number in ascending order. * @author @dailker * @param {number} n - The number to factor. * @returns {number[]} An array of all factors of n. */ function factors(n) { const result = []; for (let i = 1; i <= Math.sqrt(n); i++) { if (n % i === 0) { result.push(i); if (i !== n / i) result.push(n / i); } } return result.sort((a, b) => a - b); } exports.factors = factors;