UNPKG

es-next-tools

Version:

A comprehensive utility library for JavaScript and TypeScript that provides a wide range of functions for common programming tasks, including mathematical operations, date manipulations, array and object handling, string utilities, and more.

15 lines (14 loc) 404 B
import { gcd } from './gcd'; /** * Calculates the least common multiple (LCM) of two numbers. * @param {number} a - The first number. * @param {number} b - The second number. * @returns {number} The least common multiple of a and b. * @example * const result = lcm(4, 6); // 12 */ export function lcm(a, b) { if (a === 0 && b === 0) return 0; return Math.abs(a * b) / gcd(a, b); }