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.

Revisions

  1. Lyubaev created this gist Sep 13, 2015.
    16 changes: 16 additions & 0 deletions removeDuplicates.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    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
    }