Toolbox-XToolbox-X

Calculate HCF (GCD)

Calculates the highest common factor (greatest common divisor) of multiple numbers.

calculateHCF

The calculateHCF function calculates the highest common factor (HCF), also known as the greatest common divisor (GCD), of multiple provided numbers.

Function Signature

function calculateHCF(...numbers: Numeric[]): number

Parameters

  • numbers (Numeric[]): A list of numbers or numeric strings for which the HCF/GCD is to be calculated.

Return Value

  • number: The HCF/GCD of the provided numbers. If no valid numbers are provided, it returns 0.

Example Usage

playground.ts

Notes

  • The function works by progressively finding the HCF of pairs of numbers.
  • If no valid numbers are provided, it returns 0 as the HCF/GCD.
  • The HCF/GCD of a single number is the number itself.
  • Only integer values are considered valid for calculating HCF/GCD.

Aliases

  • calculateGCD

See Also

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

On this page