Unique takes an array and returns it with no duplicate entries.
(a []string)
| 682 | |
| 683 | // Unique takes an array and returns it with no duplicate entries. |
| 684 | func Unique(a []string) []string { |
| 685 | if len(a) < 2 { |
| 686 | return a |
| 687 | } |
| 688 | |
| 689 | sort.Strings(a) |
| 690 | idx := 1 |
| 691 | for _, val := range a { |
| 692 | if a[idx-1] == val { |
| 693 | continue |
| 694 | } |
| 695 | a[idx] = val |
| 696 | idx++ |
| 697 | } |
| 698 | return a[:idx] |
| 699 | } |
| 700 | |
| 701 | // ReadLine reads a single line from a buffered reader. The line is read into the |
| 702 | // passed in buffer to minimize allocations. This is the preferred |
no outgoing calls
no test coverage detected