From 886efa235115d8774d34e61aaefdb72603abc28f Mon Sep 17 00:00:00 2001 From: Brian Zengel Date: Fri, 18 Oct 2013 21:18:33 -0400 Subject: [PATCH] _.where definition, moved _.zipObject --- lodash/lodash-tests.ts | 14 ++++++- lodash/lodash.d.ts | 88 +++++++++++++++++++++--------------------- 2 files changed, 58 insertions(+), 44 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 81a11267a..dabbd6b4c 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -28,6 +28,12 @@ interface IStoogesAge { age: number; } +interface IStoogesCombined { + name: string; + age: number; + quotes: string[]; +} + interface IKey { dir: string; code: number; @@ -56,6 +62,11 @@ var stoogesAges: IStoogesAge[] = [ { 'name': 'larry', 'age': 50 } ]; +var stoogesCombined: IStoogesCombined[] = [ + { 'name': 'curly', 'age': 30, 'quotes': ['Oh, a wise guy, eh?', 'Poifect!'] }, + { 'name': 'moe', 'age': 40, 'quotes': ['Spread out!', 'You knucklehead!'] } +]; + var keys: IKey[] = [ { 'dir': 'left', 'code': 97 }, { 'dir': 'right', 'code': 100 } @@ -365,7 +376,8 @@ result = _.sortBy(['banana', 'strawberry', 'apple'], 'length'); (function(a, b, c, d){ return _.toArray(arguments).slice(1); })(1, 2, 3, 4); - +result = _.where(stoogesCombined, { 'age': 40 }); +result = _.where(stoogesCombined, { 'quotes': ['Poifect!'] }); diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 0de09a1f0..f9fee5695 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -451,7 +451,19 @@ declare module _ { fromIndex?: number): number; /** - * @see _.zipObject + * Creates an object composed from arrays of keys and values. Provide either a single + * two dimensional array, i.e. [[key1, value1], [key2, value2]] or two arrays, one of + * keys and one of corresponding values. + * @param keys The array of keys. + * @param values The array of values. + * @return An object composed of the given keys and corresponding values. + **/ + export function zipObject( + keys: List, + values: List): TResult; + + /** + * @see _.object **/ export function object( keys: List, @@ -1668,43 +1680,43 @@ declare module _ { **/ export function toArray(collection: Collection): T[]; - - - - - - - - - - - - - - - - - - - - - - - - - - /** - * Looks through each value in the list, returning an array of all the values that contain all - * of the key-value pairs listed in properties. - * @param list List to match elements again `properties`. - * @param properties The properties to check for on each element within `list`. - * @return The elements within `list` that contain the required `properties`. + * Performs a deep comparison of each element in a collection to the given properties + * object, returning an array of all elements that have equivalent property values. + * @param collection The collection to iterate over. + * @param properties The object of property values to filter by. + * @return A new array of elements that have the given properties. **/ export function where( list: Collection, properties: U): T[]; + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1738,17 +1750,7 @@ declare module _ { - /** - * Creates an object composed from arrays of keys and values. Provide either a single - * two dimensional array, i.e. [[key1, value1], [key2, value2]] or two arrays, one of - * keys and one of corresponding values. - * @param keys The array of keys. - * @param values The array of values. - * @return An object composed of the given keys and corresponding values. - **/ - export function zipObject( - keys: List, - values: List): TResult; +