Using a Unique Function
Previously the bug that I mentioned here `https://github.com/aditya-K2/gomp/blob/f7c22833553e99634e032bd389eae6cf1311fd1c/utils/utils.go#L147` was caused due to the replication of matched Indexes. Hence using the utils.Unique function to only get the unique elements in the slice.
This commit is contained in:
@@ -169,3 +169,15 @@ func GetMatchedString(a []int, s, color string) string {
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func Unique(intSlice []int) []int {
|
||||
keys := make(map[int]bool)
|
||||
list := []int{}
|
||||
for _, entry := range intSlice {
|
||||
if _, exists := keys[entry]; !exists {
|
||||
keys[entry] = true
|
||||
list = append(list, entry)
|
||||
}
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user