Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

chore: check slice.Contains in for range block #151

Merged
merged 2 commits into from Dec 29, 2021

Conversation

eval-exec
Copy link
Contributor

@eval-exec eval-exec commented Oct 26, 2021

// Contains Check item in slice string type
func Contains(slice []string, item string) bool {
set := make(map[string]struct{}, len(slice))
for _, s := range slice {
set[s] = struct{}{}
}
_, ok := set[item]
return ok
}

we don't need to make a map to check a slice contain a string, just do it in for range

@bxcodec
Copy link
Owner

bxcodec commented Dec 29, 2021

Thanks @eval-exec , LGTM will merged after the test

@bxcodec bxcodec merged commit e818c6c into bxcodec:master Dec 29, 2021
@bxcodec bxcodec changed the title check slice.Contains in for range block chore: check slice.Contains in for range block Dec 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants