# 判斷等比數列

// 3,6,12,24,48: 6/3 = 12/6 = 24/12
function isValid(arr){
  if(arr.length <= 2) return true
  // if have 0 ?
  let gap = arr[1]/arr[0]
  // console.log(gap)
  
  for(let i=2; i< arr.length; i++){
    if(arr[i]/arr[i-1] !== gap){
      return false
    }
  }
   return true
  
}

Last updated

Was this helpful?