Skip to content

Instantly share code, notes, and snippets.

@andy0130tw
Created April 25, 2018 21:03
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 andy0130tw/528bec01bbfff96a1244c46c61d9db00 to your computer and use it in GitHub Desktop.
Save andy0130tw/528bec01bbfff96a1244c46c61d9db00 to your computer and use it in GitHub Desktop.
FLOLAC 2018 Week 1 -- nub: filter out duplicating integers on a list
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