Skip to content

compute gcd

kgryte edited this page May 12, 2015 · 1 revision

Computes the greatest common divisor (gcd) of two or more integers.

var val = compute.gcd( [48, 18] );
// returns 6

For object arrays, provide an accessor function for accessing array values

var data = [
	{'x':48},
	{'x':18},
	{'x':30}
];

function getValue( d, i ) {
	return d.x;
}

var val = compute.gcd( data, getValue );
// returns 6

If provided an array with a length less than 2, the method returns null.

Note: the method also provides a variadic interface. See compute-gcd for additional details.

Clone this wiki locally