Created
September 13, 2015 11:17
-
-
Save Lyubaev/471180dd0bc67a43a61f to your computer and use it in GitHub Desktop.
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
| func removeDuplicates(elements []string) []string { | |
| // Use map to record duplicates as we find them. | |
| encountered := map[string]bool{} | |
| result := []string{} | |
| for v := range elements { | |
| if encountered[elements[v]] != true { | |
| // Record this element as an encountered element. | |
| encountered[elements[v]] = true | |
| // Append to result slice. | |
| result = append(result, elements[v]) | |
| } | |
| } | |
| return result | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment