Reputation: 9
I need to take odd numbers from a given list of integers to create another list.
I have written an isOdd
function, but couldn't make the rest work.
isOdd :: Integer -> Bool
isOdd n = rem (abs(n)) 2 ==1
takeOdds :: [Int] -> [Int]
...
Upvotes: 0
Views: 3113
Reputation: 679
Suppose the list is
x = [1,2,3,4,5,6]
and we can call the function odd
using the code
filter odd x
and the result is
[1,3,5]
If you want to use your own isOdd function, you can define it like
isOdd x = (mod x 2) /= 0
and the function isOdd can be called in a similar way like
filter isOdd x
The result is the same.
Upvotes: 2