Hey guys I want to create a function that takes in an array and returns true if the array is an arithmetic series and returns false if it is not. My problem is my for loop is looping through each pair to see if each consecutive pair is divisible by the difference of the first two elements. As a consequence, I am stuck and can only create a function that returns true 4 times when I do have a arithmetic series. Does anyone know how to alter my code so that I only get true or false. Here's what I have:
function arithseries(arr){
var arit = arr[1] - arr[0];
for(var i = 0; i < (arr.length - 1); i++){
if((arr[i + 1] - arr[i]) % arit === 0){
console.log("true");
}
else{
console.log("false")
}
}
}
arithseries([2,4,6,8,10])
returns
=> true
=> true
=> true
=> true