diff --git a/week10/Victor/Arith_geo.md b/week10/Victor/Arith_geo.md new file mode 100644 index 0000000..3818eae --- /dev/null +++ b/week10/Victor/Arith_geo.md @@ -0,0 +1,12 @@ +--- +Author: Victor +Date: 22-11-22 +--- + + +Have the function ArithGeo(arr) take the array of numbers stored in arr and return the string "Arithmetic" if the sequence follows an arithmetic pattern or return "Geometric" if it follows a geometric pattern. If the sequence doesn't follow either pattern return -1. An arithmetic sequence is one where the difference between each of the numbers is consistent, where as in a geometric sequence, each term after the first is multiplied by some constant or common ratio. Arithmetic example: [2, 4, 6, 8] and Geometric example: [2, 6, 18, 54]. Negative numbers may be entered as parameters, 0 will not be entered, and no array will contain all the same elements. +Examples +Input: [5,10,15] +Output: Arithmetic +Input: [2,4,16,24] +Output: -1 diff --git a/week10/Victor/Arithg_geo.js b/week10/Victor/Arithg_geo.js new file mode 100644 index 0000000..bb383fc --- /dev/null +++ b/week10/Victor/Arithg_geo.js @@ -0,0 +1,29 @@ +function ArithGeo(arr) { + + var arithDiff = arr[1] - arr[0]; + var geomDiff = arr[1] / arr[0]; + + var multiples; + + for (var i=1; i