Hello dear Community,
I want to get all elements which are on a even position in a list. It's for the implementation of a Dart game.
e.g. [((3,20),(1,19),(2,17)),((3,20),(2,12),(2,19))] -> [((3,20),(1,19),(2,17))]
So far i have tried:
positioneven n [] = []
positioneven n (x:xs) = if even n
then (x: positioneven n+1 xs)
else positioneven n+1 xs
But this of course didn't work. I would be very glad if someone can suggest me a better solution.
Thank you ! Nazar
Two useful functions for the price of one:
evens (x:xs) = x:odds xs
evens _ = []
odds (_:xs) = evens xs
odds _ = []
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With