2022-02-09 20:23:10 -03:00
|
|
|
package nostr
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
2022-11-08 07:15:08 -03:00
|
|
|
"golang.org/x/exp/constraints"
|
|
|
|
)
|
2022-02-09 20:23:10 -03:00
|
|
|
|
2022-11-08 07:15:08 -03:00
|
|
|
func Similar[E constraints.Ordered](as, bs []E) bool {
|
2022-02-09 20:23:10 -03:00
|
|
|
if len(as) != len(bs) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, a := range as {
|
|
|
|
for _, b := range bs {
|
|
|
|
if b == a {
|
|
|
|
goto next
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// didn't find a B that corresponded to the current A
|
|
|
|
return false
|
|
|
|
|
|
|
|
next:
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2022-11-08 07:15:08 -03:00
|
|
|
func ContainsPrefixOf(haystack []string, needle string) bool {
|
2022-02-09 20:23:10 -03:00
|
|
|
for _, hay := range haystack {
|
|
|
|
if strings.HasPrefix(needle, hay) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|