Skip to content

Commit

Permalink
Updating utils without dependency
Browse files Browse the repository at this point in the history
Signed-off-by: Arvinth C <arvinth.chandrasekaran@progress.com>
  • Loading branch information
ArvinthC3000 committed Oct 12, 2023
1 parent 16fe445 commit cab1ff4
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lib/arrayutils/remove_duplicate.go
@@ -1,15 +1,21 @@
package arrayutils

import (
"golang.org/x/exp/slices"
)

func RemoveStringDuplicates(inputArray []string) []string {
arrayWithoutDuplicate := []string{}
for _, item := range inputArray {
if !slices.Contains(arrayWithoutDuplicate, item) {
if !contains(arrayWithoutDuplicate, item) {
arrayWithoutDuplicate = append(arrayWithoutDuplicate, item)
}
}
return arrayWithoutDuplicate
}

func contains(arrayWithoutDuplicate []string, item string) bool {
index := -1
for i := range arrayWithoutDuplicate {
if item == arrayWithoutDuplicate[i] {
index = i
}
}
return index >= 0
}

0 comments on commit cab1ff4

Please sign in to comment.