Home

Arith-Geo

Answer

function ArithGeo(arr) { const isArithmic = arr => { let diff = arr[1] - arr[0]; for (let i = 2; i < arr.length; i++) { if (arr[i] - arr[i - 1] !== diff) { return false; } } return true; }; const isGeo = arr => { let diff = arr[1] / arr[0]; for (let i = 2; i < arr.length; i++) { if (arr[i] / arr[i - 1] !== diff) { return false; } } return true; }; if (isArithmic(arr)) return 'Arithmetic'; if (isGeo(arr)) return 'Geometric'; return -1; }