From f3c8f7bf35ae011002e81449f7b8c3b626fc22c9 Mon Sep 17 00:00:00 2001 From: brianvoe Date: Fri, 25 Oct 2024 21:27:18 -0500 Subject: [PATCH] products - added check for dup --- product.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/product.go b/product.go index 3179cc33..63dfd73f 100644 --- a/product.go +++ b/product.go @@ -169,11 +169,20 @@ func ProductAudience() []string { return productAudience(GlobalFaker) } func (f *Faker) ProductAudience() []string { return productAudience(f) } func productAudience(f *Faker) []string { - targetAudiences := []string{} + audiences := []string{} for i := 0; i < number(f, 1, 2); i++ { - targetAudiences = append(targetAudiences, getRandValue(f, []string{"product", "target_audience"})) + // Check if the target audience is already in the list + // If it is, generate a new target audience + for { + audience := getRandValue(f, []string{"product", "target_audience"}) + // Check if in array + if !stringInSlice(audience, audiences) { + audiences = append(audiences, audience) + break + } + } } - return targetAudiences + return audiences } // ProductDimension will generate a random product dimension