Last active
May 12, 2018 08:45
-
-
Save taiansu/3c041a7b972701c4154e651b4bcc4693 to your computer and use it in GitHub Desktop.
Flolac week of code 1: nub
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
nub' :: [Int] -> [Int] | |
nub' = foldr f [] where | |
f x xs | |
| x `elem` xs = xs | |
| otherwise = x:xs | |
-- without using `elem` | |
nub'' :: [Int] -> [Int] | |
nub'' = foldr f [] where | |
f x xs | |
| length (filter (x ==) xs) > 0 = xs | |
| otherwise = x:xs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment