gtx


Branch: develop

Author
Spike Lindsey <spike01@gmail.com>
Date
Jan. 30 '23 17:04:18
Commit
750acd15e3c8817ba1c2c3a49454c6be94e547cf
Parent
0bf981b17764df81150e432a15e3fae61c7e3abd
Changes
diff --git a/helper.go b/helper.go
index d0a380e..67954e7 100644
--- a/helper.go
+++ b/helper.go
@@ -1,9 +1,5 @@
 package main
 
-import (
-	"reflect"
-)
-
 type void struct{}
 
 // Helps decide if value contained in slice.
@@ -20,12 +16,16 @@ func contains(s []string, n string) bool {
 
 // Helps clear duplicates in slice.
 // https://stackoverflow.com/questions/66643946/how-to-remove-duplicates-strings-or-int-from-slice-in-go
-func dedupe(input []string) []reflect.Value {
+func dedupe(input []string) []string {
 	set := make(map[string]void)
+	list := []string{}
 
 	for _, v := range input {
-		set[v] = void{}
+		if _, ok := set[v]; !ok {
+			set[v] = void{}
+			list = append(list, v)
+		}
 	}
 
-	return reflect.ValueOf(set).MapKeys()
+	return list
 }
diff --git a/helper_test.go b/helper_test.go
index f62d053..0b551b0 100644
--- a/helper_test.go
+++ b/helper_test.go
@@ -17,3 +17,11 @@ func TestContains(t *testing.T) {
 		}
 	}
 }
+
+func TestDedupe(t *testing.T) {
+  dupes := []string{"one", "one", "two", "three", "three", "three"}
+
+  if len(dedupe(dupes)) != 3 {
+    t.Fail()
+  }
+}