Toolbox-XToolbox-X

Factors of a Number

Efficiently computes all positive integer factors (divisors) of a number.

getFactors

The getFactors function efficiently computes all positive integer factors (divisors) of a number.

Function Signature

function getFactors(int: Numeric | undefined): number[]

Parameters

  • int (Numeric | undefined): A numeric value or numeric string to find factors for. Can also be undefined.

Return Value

  • number[]: An array of positive integer factors in ascending order for valid input, or an empty array for invalid inputs (e.g. non-integers, negative numbers, or undefined).

Example Usage

playground.ts

Notes

  • Uses the square root method for optimal performance (O(√n) complexity).
  • Factors are always returned in ascending order.

Aliases

  • factorsOf
  • getDivisors

See Also

Last updated: Sun, Jun 14, 2026 07:06:16AM (UTC)

On this page