Skip to content

Instantly share code, notes, and snippets.

@DavidLee18
DavidLee18 / splitArray.hs
Last active May 4, 2024 21:29
Split Array into odds and even ones
main :: IO ()
main = print $ splitArray [1, 2, 3, 7, 2, 4, 5]
splitArray :: [Int] -> ([Int], [Int])
splitArray [] = ([], [])
splitArray (x:xs) | even x = (x:evens, odds)
| otherwise = (evens, x:odds)
where (evens, odds) = splitArray xs