From 166f6e6266a733e49ecc28181c909cbf1eefbc1e Mon Sep 17 00:00:00 2001 From: a-s-z-home Date: Sat, 3 Nov 2018 20:20:00 +0100 Subject: [PATCH] Added string array helper functions Contains and Find. --- src/duplicacy_utils.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/duplicacy_utils.go b/src/duplicacy_utils.go index 1bfa728..de18c90 100644 --- a/src/duplicacy_utils.go +++ b/src/duplicacy_utils.go @@ -474,3 +474,24 @@ func MinInt(x, y int) int { } return y } + +// Contains tells whether a contains x. +func Contains(a []string, x string) bool { + for _, n := range a { + if x == n { + return true + } + } + return false +} + +// Find returns the smallest index i at which x == a[i], +// or len(a) if there is no such index. +func Find(a []string, x string) int { + for i, n := range a { + if x == n { + return i + } + } + return len(a) +} \ No newline at end of file