diff options
Diffstat (limited to 'helpers/general.go')
-rw-r--r-- | helpers/general.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/helpers/general.go b/helpers/general.go index 731452d9d..2237125d7 100644 --- a/helpers/general.go +++ b/helpers/general.go @@ -467,3 +467,27 @@ func NormalizeHugoFlags(f *pflag.FlagSet, name string) pflag.NormalizedName { } return pflag.NormalizedName(name) } + +// DiffStringSlices returns the difference between two string slices. +// Useful in tests. +// See: +// http://stackoverflow.com/questions/19374219/how-to-find-the-difference-between-two-slices-of-strings-in-golang +func DiffStringSlices(slice1 []string, slice2 []string) []string { + diffStr := []string{} + m := map[string]int{} + + for _, s1Val := range slice1 { + m[s1Val] = 1 + } + for _, s2Val := range slice2 { + m[s2Val] = m[s2Val] + 1 + } + + for mKey, mVal := range m { + if mVal == 1 { + diffStr = append(diffStr, mKey) + } + } + + return diffStr +} |