Skip to content

Instantly share code, notes, and snippets.

@Lyubaev
Created September 13, 2015 11:17
Show Gist options
  • Save Lyubaev/471180dd0bc67a43a61f to your computer and use it in GitHub Desktop.
Save Lyubaev/471180dd0bc67a43a61f to your computer and use it in GitHub Desktop.
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