Last active
December 15, 2015 11:18
-
-
Save fabioyamate/5251624 to your computer and use it in GitHub Desktop.
Given a list of list of integers, return the first item in each sublist, in a way that no duplication is occurred
This file contains hidden or 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
| (defn add-first-uniq [target coll] | |
| (cond (not (contains? target (first coll))) | |
| (conj target (first coll)) | |
| :else | |
| (add-first-uniq target (rest coll)))) | |
| (reduce add-first-uniq | |
| #{} | |
| '((1 2 3) (1 2) (4 5))) | |
| ; => #{1 2 4} |
This file contains hidden or 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
| (facts | |
| (f '((1 4 5) (1 4 2) (10 4 1))) => '(1 4 10) | |
| (f '()) => '() | |
| (f '((1 2) () (3 4))) => (1 3)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment