Skip to content

Instantly share code, notes, and snippets.

@DavidLee18
Last active May 4, 2024 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavidLee18/b63c61be108b4b38715f74c8b4dcd558 to your computer and use it in GitHub Desktop.
Save DavidLee18/b63c61be108b4b38715f74c8b4dcd558 to your computer and use it in GitHub Desktop.
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
def splitArray(array):
even = []
odd = []
for i in array:
if i % 2 == 0:
even.append(i)
else:
odd.append(i)
return even, odd
splitArray([1, 2, 3, 7, 2, 4, 5])
SplitArray ← ∩▽¬,,=0◿2.
SplitArray [1 2 3 7 2 4 5]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment