# compute-gcd **Repository Path**: ArkTSCentralRepository/compute-gcd ## Basic Information - **Project Name**: compute-gcd - **Description**: Computes the greatest common divisor (gcd). - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-03-23 - **Last Updated**: 2026-03-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # compute-gcd 基于[compute-gcd](https://www.npmjs.com/package/compute-gcd)原库1.2.1版本进行适配 ## Install ```sh ohpm install compute-gcd ``` ## Usage > Computes the [greatest common divisor](http://en.wikipedia.org/wiki/Greatest_common_divisor) (gcd). Note: the gcd is also known as the __greatest common factor__ (gcf), __highest common factor__ (hcf), __highest common divisor__, and __greatest common measure__ (gcm). ``` typescript import gcd from 'compute-gcd'; ``` #### gcd( a, b[, c,...,n] ) Computes the [greatest common divisor](http://en.wikipedia.org/wiki/Greatest_common_divisor) (gcd) of two or more `integers`. ``` typescript let val = gcd( 48, 18 ); // returns 6 let val = gcd( 8, 12, 16 ); // returns 4 ``` #### gcd( arr[, accessor] ) Computes the [greatest common divisor](http://en.wikipedia.org/wiki/Greatest_common_divisor) (gcd) of two or more `integers`. ``` typescript let val = gcd( [48, 18] ); // returns 6 let val = gcd( [8, 12, 16] ); // returns 4 ``` For object `arrays`, provide an accessor `function` for accessing `array` values ``` javascript const data = [ ['beep', 4], ['boop', 8], ['bap', 12], ['baz', 16] ]; const getValue = (d: (string | number)[], i: number) => { return d[1]; }; let val = gcd( data, getValue ); // returns 4 ``` ## Notes - For more than 3 values, a performance gain can be achieved if the values are sorted in ascending order. - If provided an `array` with a length less than `2` or a single `integer` argument, the function returns `null`.