Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use generic types for choice and shuffle methods #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions @types/PRNG.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,11 @@ declare class PRNG {
* random.choice(arr); // 4
*
* @public
* @param {any[]} array -> Array of any type from which we randomly select one item.
* @returns {any} A single item from the array of type ?.
* @template T
* @param {T[]} array -> Array of any type from which we randomly select one item.
* @returns {T} A single item from the array of type ?.
*/
public choice(array: any[]): any;
public choice<T>(array: T[]): T;
/**
* Randomly shuffles the given array using the fisher-yates algorithm.
*
Expand All @@ -200,11 +201,12 @@ declare class PRNG {
* console.log(shuffled); // [4, 2, 3, 1]
*
* @public
* @param {any[]} array -> Array of any type to be shuffled.
* @template T
* @param {T[]} array -> Array of any type to be shuffled.
* @param {boolean} inPlace -> Shuffle the array (true) or shuffle a copy of array (false).
* @returns {any[]} Array shuffled (inPlace === false), shuffled copy of array (inPlace === true).
* @returns {T[]} Array shuffled (inPlace === false), shuffled copy of array (inPlace === true).
*/
public shuffle(array: any[], inPlace?: boolean): any[];
public shuffle<T>(array: T[], inPlace?: boolean): T[];
/**
* Creates an array of the given size populated with the result of the mapFn.
*
Expand Down