Skip to content

dnydxn/gcdlcm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gcdlcm

Fast and simple gcd/lcm implementation in JavaScript using the Euclidean algorithm.

Installation

npm

npm i @dnydxn/gcdlcm

Usage

Import

const { gcd, lcm } = require("@dnydxn/gcdlcm");     // cjs

// or

import gcdlcm from "@dnydxn/gcdlcm";                // mjs
const { gcd, lcm } = gcdlcm;

Examples

gcd(2, 3)   // 1
gcd(2, 4)   // 2

lcm(2, 3)   // 6
lcm(2, 4)   // 4

The gcdn/lcmn functions can take an arbitrary amount of parameters.
Note that gcd/lcm is faster when only two parameters are given.

const { gcdn, lcmn } = require("@dnydxn/gcdlcm");

gcdn(2, 3, 4)       // 1
gcdn(2, 4, 6, 8)    // 2

lcmn(2, 3, 4)       // 12
lcmn(2, 4, 5, 6)    // 60

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages