Skip to content

Commit

Permalink
refactor: clarify array sample function documentation (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
felixranesberger committed Mar 6, 2023
1 parent 2193288 commit 1106872
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,13 @@ export function clampArrayRange(n: number, arr: readonly unknown[]) {
}

/**
* Get random items from an array
* Get random item(s) from an array
*
* @category Array
* @param arr
* @param quantity - quantity of random items which will be returned
*/
export function sample<T>(arr: T[], count: number) {
return Array.from({ length: count }, _ => arr[Math.round(Math.random() * (arr.length - 1))])
export function sample<T>(arr: T[], quantity: number) {
return Array.from({ length: quantity }, _ => arr[Math.round(Math.random() * (arr.length - 1))])
}

/**
Expand Down

0 comments on commit 1106872

Please sign in to comment.