mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
_.sample definitions
This commit is contained in:
@@ -342,6 +342,9 @@ result = <number[]>_.reject([1, 2, 3, 4, 5, 6], function(num) { return num % 2 =
|
||||
result = <IFoodCombined[]>_.reject(foodsCombined, 'organic');
|
||||
result = <IFoodCombined[]>_.reject(foodsCombined, { 'type': 'fruit' });
|
||||
|
||||
result = <number>_.sample([1, 2, 3, 4]);
|
||||
result = <number[]>_.sample([1, 2, 3, 4], 2);
|
||||
|
||||
result = <boolean>_.some([null, 0, 'yes', false], Boolean);
|
||||
result = <boolean>_.some(foodsCombined, 'organic');
|
||||
result = <boolean>_.some(foodsCombined, { 'type': 'meat' });
|
||||
|
||||
Vendored
+14
-12
@@ -1521,6 +1521,20 @@ declare module _ {
|
||||
collection: Collection<T>,
|
||||
whereValue: Dictionary<any>): T[];
|
||||
|
||||
/**
|
||||
* Retrieves a random element or n random elements from a collection.
|
||||
* @param collection The collection to sample.
|
||||
* @return Returns the random sample(s) of collection.
|
||||
**/
|
||||
export function sample<T>(collection: Collection<T>): T;
|
||||
|
||||
/**
|
||||
* @see _.sample
|
||||
* @param n The number of elements to sample.
|
||||
**/
|
||||
export function sample<T>(collection: Collection<T>, n: number): T[];
|
||||
|
||||
|
||||
/**
|
||||
* Checks if the callback returns a truey value for any element of a collection. The function
|
||||
* returns as soon as it finds a passing value and does not iterate over the entire collection.
|
||||
@@ -1649,18 +1663,6 @@ declare module _ {
|
||||
**/
|
||||
export function shuffle<T>(list: Collection<T>): T[];
|
||||
|
||||
/**
|
||||
* Produce a random sample from the `list`. Pass a number to return `n` random elements from the list. Otherwise a single random item will be returned.
|
||||
* @param list List to sample.
|
||||
* @return Random sample of `n` elements in `list`.
|
||||
**/
|
||||
export function sample<T>(list: Collection<T>, n: number): T[];
|
||||
|
||||
/**
|
||||
* @see _.sample
|
||||
**/
|
||||
export function sample<T>(list: Collection<T>): T;
|
||||
|
||||
/**
|
||||
* Converts the list (anything that can be iterated over), into a real Array. Useful for transmuting
|
||||
* the arguments object.
|
||||
|
||||
Reference in New Issue
Block a user