Last active
May 4, 2024 21:29
-
-
Save DavidLee18/b63c61be108b4b38715f74c8b4dcd558 to your computer and use it in GitHub Desktop.
Split Array into odds and even ones
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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