Array Challenge | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Array Challenge

"Have the function Array Challenge(arr) take the array of numbers stored in array 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"

12th Dec 2021, 7:55 AM
Msawenkosi Zuma
3 Answers
+ 1
I'm not getting the Geometric sequence example ...
12th Dec 2021, 9:35 AM
Ipang
+ 1
No I haven't, I don't know how to check the Geometric sequence. I'm not good in maths but this is interesting.
12th Dec 2021, 1:33 PM
Ipang
0
How did you do it?
12th Dec 2021, 12:11 PM
Msawenkosi Zuma