From 2f78fc207e623e77f5b33856a7c30fa91e6f7c9b Mon Sep 17 00:00:00 2001 From: viehlieb Date: Mon, 13 Feb 2023 18:48:28 +0100 Subject: [PATCH] move find x not in y for int64 slices to utils --- pkg/utils/slice_difference.go | 37 +++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 pkg/utils/slice_difference.go diff --git a/pkg/utils/slice_difference.go b/pkg/utils/slice_difference.go new file mode 100644 index 000000000..cc01fad10 --- /dev/null +++ b/pkg/utils/slice_difference.go @@ -0,0 +1,37 @@ +// Vikunja is a to-do list application to facilitate your life. +// Copyright 2018-2021 Vikunja and contributors. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public Licensee as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public Licensee for more details. +// +// You should have received a copy of the GNU Affero General Public Licensee +// along with this program. If not, see . + +package utils + +// find the elements which appear in slice1,but not in slice2 +func NotIn(slice1 []int64, slice2 []int64) []int64 { + var diff []int64 + + for _, s1 := range slice1 { + found := false + for _, s2 := range slice2 { + if s1 == s2 { + found = true + break + } + } + // int64 not found. We add it to return slice + if !found { + diff = append(diff, s1) + } + } + return diff +}