math - How to find if an array of numbers is a geometric sequence in javascript -


i don't know start this. missing knowledge need know? hints give me or solution dissect?

a geometric sequence ar0, ar1, ar2, ... yes?

function isgeometric(arr) {     if (arr.length <= 2) return true; // special cases     var = arr[1],                   // dont need test before         r = / arr[0],               // ratio of first 2         i;     (i = 2; < arr.length; ++i)         if ((a *= r) !== arr[i])             return false;     return true; }  isgeometric([2, 4, 8]); // true isgeometric([2, 4, 5]); // false 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -