Skip to content

Commit 1106872

Browse files
refactor: clarify array sample function documentation (antfu#30)
1 parent 2193288 commit 1106872

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/array.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,13 @@ export function clampArrayRange(n: number, arr: readonly unknown[]) {
180180
}
181181

182182
/**
183-
* Get random items from an array
183+
* Get random item(s) from an array
184184
*
185-
* @category Array
185+
* @param arr
186+
* @param quantity - quantity of random items which will be returned
186187
*/
187-
export function sample<T>(arr: T[], count: number) {
188-
return Array.from({ length: count }, _ => arr[Math.round(Math.random() * (arr.length - 1))])
188+
export function sample<T>(arr: T[], quantity: number) {
189+
return Array.from({ length: quantity }, _ => arr[Math.round(Math.random() * (arr.length - 1))])
189190
}
190191

191192
/**

0 commit comments

Comments
 (0)