Skip to content

Commit 5e596a9

Browse files
committed
fix: eternal in getRandomSample if passed empty array
1 parent 8067300 commit 5e596a9

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/utils/functions/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export const getRandomSample = <Type> (population: Array<Type>, n: number) => {
8282
const indexes = [] as number[]
8383
const indexesObject = {} as Record<number, boolean>
8484

85-
while (indexes.length < n) {
85+
while (indexes.length < n && indexes.length < population.length) {
8686
const random = Math.floor(Math.random() * population.length)
8787
if (random in indexesObject) continue
8888
indexesObject[random] = true

0 commit comments

Comments
 (0)