26
utils/main.go
Normal file
26
utils/main.go
Normal file
@ -0,0 +1,26 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func Dedup(input string) string {
|
||||
unique := []string{}
|
||||
words := strings.Split(input, " ")
|
||||
for _, word := range words {
|
||||
if contains(unique, word) {
|
||||
continue
|
||||
}
|
||||
unique = append(unique, word)
|
||||
}
|
||||
return strings.Join(unique, " ")
|
||||
}
|
||||
|
||||
func contains(strs []string, str string) bool {
|
||||
for _, s := range strs {
|
||||
if s == str {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
Reference in New Issue
Block a user