mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
_.filter/_.select definitions
This commit is contained in:
+8
-17
@@ -227,6 +227,14 @@ result = <boolean>_.every(stoogesAges, { 'age': 50 });
|
||||
result = <boolean>_.all(stoogesAges, 'age');
|
||||
result = <boolean>_.all(stoogesAges, { 'age': 50 });
|
||||
|
||||
result = <number[]>_.filter([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; });
|
||||
result = <IFoodCombined[]>_.filter(foodsCombined, 'organic');
|
||||
result = <IFoodCombined[]>_.filter(foodsCombined, { 'type': 'fruit' });
|
||||
|
||||
result = <number[]>_.select([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; });
|
||||
result = <IFoodCombined[]>_.select(foodsCombined, 'organic');
|
||||
result = <IFoodCombined[]>_.select(foodsCombined, { 'type': 'fruit' });
|
||||
|
||||
result = <number>_.find([1, 2, 3, 4], function(num) {
|
||||
return num % 2 == 0;
|
||||
});
|
||||
@@ -282,12 +290,6 @@ result = <boolean>_.some(foodsCombined, { 'type': 'meat' });
|
||||
//WHAT'S LEFT
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
_.each([1, 2, 3], (num) => alert(num.toString()));
|
||||
_.each({ one: 1, two: 2, three: 3 }, (value) => alert(value.toString()));
|
||||
|
||||
_.map([1, 2, 3], (num) => num * 3);
|
||||
_.map({ one: 1, two: 2, three: 3 }, (value: number, key?: string) => value * 3);
|
||||
|
||||
var sum = _.reduce([1, 2, 3], (memo, num) => memo + num, 0);
|
||||
sum = _.reduce([1, 2, 3], (memo, num) => memo + num); // memo is optional #issue 5 github
|
||||
|
||||
@@ -296,20 +298,11 @@ var flat = _.reduceRight(list, (a, b) => a.concat(b), []);
|
||||
|
||||
var even = _.find([1, 2, 3, 4, 5, 6], (num) => num % 2 == 0);
|
||||
|
||||
var evens = _.filter([1, 2, 3, 4, 5, 6], (num) => num % 2 == 0);
|
||||
|
||||
var listOfPlays = [{ title: "Cymbeline", author: "Shakespeare", year: 1611 }, { title: "The Tempest", author: "Shakespeare", year: 1611 }, { title: "Other", author: "Not Shakespeare", year: 2012 }];
|
||||
_.where(listOfPlays, { author: "Shakespeare", year: 1611 });
|
||||
|
||||
var odds = _.reject([1, 2, 3, 4, 5, 6], (num) => num % 2 == 0);
|
||||
|
||||
_.every([true, 1, null, 'yes'], _.identity);
|
||||
_.every<{}>([true, 1, null, 'yes']);
|
||||
|
||||
_.any([null, 0, 'yes', false]);
|
||||
|
||||
_.contains([1, 2, 3], 3);
|
||||
|
||||
_.invoke([[5, 1, 7], [3, 2, 1]], 'sort');
|
||||
|
||||
var stooges = [{ name: 'moe', age: 40 }, { name: 'larry', age: 50 }, { name: 'curly', age: 60 }];
|
||||
@@ -336,8 +329,6 @@ _(stooges)
|
||||
.indexBy('age')
|
||||
.value()['40'].age;
|
||||
|
||||
_.countBy<number>([1, 2, 3, 4, 5], (num) => (num % 2 == 0) ? 'even' : 'odd');
|
||||
|
||||
_.shuffle([1, 2, 3, 4, 5, 6]);
|
||||
|
||||
(function(a, b, c, d){ return _.toArray(arguments).slice(1); })(1, 2, 3, 4);
|
||||
|
||||
Vendored
+61
-20
@@ -932,6 +932,66 @@ declare module _ {
|
||||
collection: Collection<T>,
|
||||
whereValue: Dictionary<any>): boolean;
|
||||
|
||||
/**
|
||||
* Iterates over elements of a collection, returning an array of all elements the
|
||||
* callback returns truey for. The callback is bound to thisArg and invoked with three
|
||||
* arguments; (value, index|key, collection).
|
||||
*
|
||||
* If a property name is provided for callback the created "_.pluck" style callback will
|
||||
* return the property value of the given element.
|
||||
*
|
||||
* If an object is provided for callback the created "_.where" style callback will return
|
||||
* true for elements that have the properties of the given object, else false.
|
||||
* @param collection The collection to iterate over.
|
||||
* @param callback The function called per iteration.
|
||||
* @param context The this binding of callback.
|
||||
* @return Returns a new array of elements that passed the callback check.
|
||||
**/
|
||||
export function filter<T>(
|
||||
collection: Collection<T>,
|
||||
callback: ListIterator<T, boolean>,
|
||||
thisArg?: any): T[];
|
||||
|
||||
/**
|
||||
* @see _.filter
|
||||
* @param pluckValue _.pluck style callback
|
||||
**/
|
||||
export function filter<T>(
|
||||
collection: Collection<T>,
|
||||
pluckValue: string): T[];
|
||||
|
||||
/**
|
||||
* @see _.filter
|
||||
* @param pluckValue _.pluck style callback
|
||||
**/
|
||||
export function filter<T>(
|
||||
collection: Collection<T>,
|
||||
whereValue: Dictionary<any>): T[];
|
||||
|
||||
/**
|
||||
* @see _.filter
|
||||
**/
|
||||
export function select<T>(
|
||||
collection: Collection<T>,
|
||||
callback: ListIterator<T, boolean>,
|
||||
thisArg?: any): T[];
|
||||
|
||||
/**
|
||||
* @see _.filter
|
||||
* @param pluckValue _.pluck style callback
|
||||
**/
|
||||
export function select<T>(
|
||||
collection: Collection<T>,
|
||||
pluckValue: string): T[];
|
||||
|
||||
/**
|
||||
* @see _.filter
|
||||
* @param pluckValue _.pluck style callback
|
||||
**/
|
||||
export function select<T>(
|
||||
collection: Collection<T>,
|
||||
whereValue: Dictionary<any>): T[];
|
||||
|
||||
/**
|
||||
* Iterates over elements of a collection, returning the first element that the callback
|
||||
* returns truey for. The callback is bound to thisArg and invoked with three arguments;
|
||||
@@ -1307,26 +1367,7 @@ declare module _ {
|
||||
memo?: TResult,
|
||||
context?: any): TResult;
|
||||
|
||||
/**
|
||||
* Looks through each value in the list, returning an array of all the values that pass a truth
|
||||
* test (iterator). Delegates to the native filter method, if it exists.
|
||||
* @param list Filter elements out of this list.
|
||||
* @param iterator Filter iterator function for each element in `list`.
|
||||
* @param context `this` object in `iterator`, optional.
|
||||
* @return The filtered list of elements.
|
||||
**/
|
||||
export function filter<T>(
|
||||
list: Collection<T>,
|
||||
iterator: ListIterator<T, boolean>,
|
||||
context?: any): T[];
|
||||
|
||||
/**
|
||||
* @see _.filter
|
||||
**/
|
||||
export function select<T>(
|
||||
list: Collection<T>,
|
||||
iterator: ListIterator<T, boolean>,
|
||||
context?: any): T[];
|
||||
|
||||
|
||||
/**
|
||||
* Looks through each value in the list, returning an array of all the values that contain all
|
||||
|
||||
Reference in New Issue
Block a user