An alternating array is a list of any length in which two (not necessarily different) values are alternating. That is to say, all even-indexed items are equal, and all odd-indexed items are equal.
Your task is to write a program or function which, when given a list of positive integers, outputs/returns
truthy if it is alternating and
This is code-golf, so the shortest code (in bytes) wins!
 -> True  -> True [1,1] -> True [1,2,1] -> True
Other Test Cases:
[1,2,1,2] -> True [3,4,3] -> True [10,5,10,5,10] -> True [10,11] -> True [9,9,9,9,9] -> True [5,4,3,5,4,3] -> False [3,2,1,2,1,2] -> False [1,2,1,2,1,1,2] -> False [2,2,3,3] -> False [2,3,3,2] -> False
Here is an example you can test your solution against, written in Python 3 (not golfed):
def is_alternating(array): for i in range(len(array)): if array[i] != array[i%2]: return False return True