Skip to content

Commit

Permalink
products - added check for dup
Browse files Browse the repository at this point in the history
  • Loading branch information
brianvoe committed Oct 26, 2024
1 parent 1f5908a commit f3c8f7b
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions product.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f3c8f7b

Please sign in to comment.