all repos — honk @ a41cef6d2b83f7cec8c1846c64362ddac8067307

my fork of honk

rewrite oneofakind with map since we're starting to see longer arrays
Ted Unangst tedu@tedunangst.com
Sat, 19 Oct 2019 15:37:33 -0400
commit

a41cef6d2b83f7cec8c1846c64362ddac8067307

parent

71e63a5d2da9f2f20d762200b9088f580e51e87c

1 files changed, 9 insertions(+), 10 deletions(-)

jump to
M fun.gofun.go

@@ -538,18 +538,17 @@ return honk.Audience[0] == thewholeworld

} func oneofakind(a []string) []string { - var x []string - for n, s := range a { - if s != "" { - x = append(x, s) - for i := n + 1; i < len(a); i++ { - if a[i] == s { - a[i] = "" - } - } + seen := make(map[string]bool) + seen[""] = true + j := 0 + for _, s := range a { + if !seen[s] { + seen[s] = true + a[j] = s + j++ } } - return x + return a[:j] } var ziggies = make(map[string]*rsa.PrivateKey)