Created
April 25, 2018 21:03
-
-
Save andy0130tw/528bec01bbfff96a1244c46c61d9db00 to your computer and use it in GitHub Desktop.
FLOLAC 2018 Week 1 -- nub: filter out duplicating integers on a list
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] -> [Int] | |
nub' rs [] = reverse rs | |
nub' rs (x:xs) | elem x rs = nub' rs xs | |
| otherwise = nub' (x:rs) xs | |
nub :: [Int] -> [Int] | |
nub = nub' [] | |
{- | |
some test cases: | |
* nub [] == [] | |
* nub [1, 2, 3, 4] == [1, 2, 3, 4] | |
* nub [1, 1, 1, 2] == [1, 2] | |
* nub [1, 2, 2, 5, 3, 5] == [1, 2, 5, 3] | |
* nub [1, 2, 3, 4, 2, 3, 1, 5, 4, 3] == [1, 2, 3, 4, 5] | |
-} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment