Monday 6 June 2016

Haskell: Double all odd numbers in a list

Prelude> let doubleOdds list = [2 * x | x <- list, odd x]
Prelude> 
Prelude> doubleOdds [1, 2, 3, 4, 5, 6, 7]
[2,6,10,14]

Previous                                                 Next                                                 Home

No comments:

Post a Comment