Question 3-2

Write a Haskell function everyOther which takes a list and returns a list containing every other element of it. For example, everyOther [1..10] should return the list [1,3,5,7,9]. Your function should be able to work for lists of any length (whether even or odd).

Solution

everyOther [] = []
everyOther [a] = [a]
everyOther (x1:x2:xs) = x1:xs

Back to Review for Quiz 3