Skip to content
JavaScript function to get GCF (greatest common factor) and LCM (least common multiple)
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
LICENSE
README.md
the.js
the.py

README.md

glc.js

JavaScript function to get GCF (greatest common factor) and LCM (least common multiple)

Usage

glc([list_of_positive_integers])

Example: glc([8, 16, 18])

Input

This function receives only an array of positive integers from 2 to 1,000,000 (1 million).

The array length is limited to 20

It only receives one argument (input).

Output

For valid input, the output will be an object.

The object consists of:

{
    duration: "process in milliseconds",
    input: [your_input_array],
    output: {
        gcf_array: [GCF_LIST],
        gcf: integer_multiplication_from_GCF_LIST,
        lcm_array: [LCM_LIST],
        lcm: integer_multiplication_from_LCM_LIST
}

Examples

VALID INPUT

glc([8, 16, 18]) → input is [8, 16, 18]valid input

Output (object):

{
    duration: "1 ms",
    input: [8, 16, 18],
    output: {
        gcf: 2,
        gcf_array: [1, 2],        
        lcm: 144,
        lcm_array: [1, 2, 2, 2, 2, 3, 3]
}

INVALID INPUT

glc(4) → input is 4invalid input

Output (string):

Error: invalid input → must be array of positive integers → max each 1,000,000 (one million)

BASED ON CONTINUOUS DIVISION

More info on Monkey Raptor

Python

Equivalency is the.py

It is with similar input (limitation) and output form (type).

You can’t perform that action at this time.