題目連結
https://www.codewars.com/kata/52f677797c461daaf7000740
解法
function solution(X) {
function gcd(a, b) {
if (b === 0) {
return a;
}
return gcd(b, a % b);
}
const n = X.length;
let result = X[0];
for (let i = 1; i < n; i++) {
result = gcd(result, X[i]);
}
return result * n;
}