Hello,
I have to double every second element from the right.
So for a even length array that means : 1 , 3 , 5 and so on
and for a non even lenght that means the 2,4 and so on.
So I thought I could solve that on this way :
-- | Doubles every second number from the right.
doubleEveryOther :: [Integer] -> [Integer]
doubleEveryOther [] = []
doubleEveryOther (x:[]) = [x]
doubleEveryOther (x:(y:zs))
| ((x:(y:zs)).length) `mod` 2 /= 0 = [x] ++ (y * 2) :
doubleEveryOther zs
| otherwise = [x *2] ++ y : doubleEveryOther zs
but this does not work because I see this error message :
src/Main.hs@14:8-14:16
Couldn't match expected type Int
-> c0 with actual type
[Integer]
In the first argument of (.), namely (x : (y : zs))
In the first argument of mod, namely ((x : (y : zs)) .
length)
In the first argument of (/=), namely ((x : (y : zs)) .
length) `mod` 2
Can anyone give me a better way to check if I have a even or odd
length array ?
Roelof