Skip to content

Instantly share code, notes, and snippets.

@hdonnay
Created June 30, 2016 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hdonnay/1f45c677464012d655cdc0f430256b8e to your computer and use it in GitHub Desktop.
Save hdonnay/1f45c677464012d655cdc0f430256b8e to your computer and use it in GitHub Desktop.
// This is something like n^2 worst-case.
//
// []string must be sorted
func diffStrings(new, old []string) (added, removed []string) {
Add:
for _, x := range new {
for _, y := range old {
if x == y {
continue Add
}
}
added = append(added, x)
}
Rem:
for _, x := range old {
for _, y := range new {
if x == y {
continue Rem
}
}
removed = append(removed, x)
}
return added, removed
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment