Skip to content

Commit

Permalink
Merge pull request #41 from codecrafters-io/parser-ext-patch
Browse files Browse the repository at this point in the history
Fix issue with RandomElementsFromArray function
  • Loading branch information
ryan-gang authored Jul 12, 2024
2 parents 66ee748 + afd8d47 commit 0e4cea8
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions random/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,9 @@ func RandomElementsFromArray[T any](arr []T, count int) []T {
arr = append(arr, arr...)
}
elements := make([]T, count)
for i, randIndex := range rand.Perm(len(elements)) {
elements[i] = elements[randIndex]
for i, randIndex := range rand.Perm(len(arr))[:count] {
elements[i] = arr[randIndex]
}
return elements
}

func contains(arr []int, val int) bool {
for _, v := range arr {
if v == val {
return true
}
}
return false
return elements
}

0 comments on commit 0e4cea8

Please sign in to comment.