function generalizedGCD(num, arr) { return arr.reduce((acc, curr, idx, data) => { return gcd(acc, curr); }, arr.shift()); } var gcd = (a, b) => { if (a == 0) return b; return gcd(b % a, a); };