From c47e9a7ddb15728ccb24f7a3e4de0959d28c2799 Mon Sep 17 00:00:00 2001 From: Brian Zengel Date: Sun, 13 Oct 2013 19:17:28 -0400 Subject: [PATCH] definitions for _.initial and _.intersection --- lodash/lodash-tests.ts | 14 +++++++++++-- lodash/lodash.d.ts | 47 ++++++++++++++++++++++++++++++++++++++---- 2 files changed, 55 insertions(+), 6 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 1c3401620..530259311 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -105,6 +105,16 @@ result = _.indexOf([1, 2, 3, 1, 2, 3], 2); result = _.indexOf([1, 2, 3, 1, 2, 3], 2, 3); result = _.indexOf([1, 1, 2, 2, 3, 3], 2, true); +result = _.initial([1, 2, 3]); +result = _.initial([1, 2, 3], 2); +result = _.initial([1, 2, 3], function(num) { + return num > 1; +}); +result = _.initial(foodsOrganic, 'organic'); +result = _.initial(foodsType, { 'type': 'vegetable' }); + +result = _.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]); + //////////////////////////////////////////////////////////////////////////////////////// //WHAT'S LEFT //////////////////////////////////////////////////////////////////////////////////////// @@ -174,7 +184,7 @@ _.size({ one: 1, two: 2, three: 3 }); /////////////////////////////////////////////////////////////////////////////////////// -_.initial([5, 4, 3, 2, 1]); + _.last([5, 4, 3, 2, 1]); @@ -183,7 +193,7 @@ _.last([5, 4, 3, 2, 1]); _.without([1, 2, 1, 0, 3, 1, 4], 0, 1); _.union([1, 2, 3], [101, 2, 1, 10], [2, 1]); -_.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]); + _.difference([1, 2, 3, 4, 5], [5, 2, 10]); _.uniq([1, 2, 1, 3, 1, 4]); _.zip(['moe', 'larry', 'curly'], [30, 40, 50], [true, false, false]); diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index b5f6b882c..a5c5e5126 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -710,15 +710,54 @@ declare module _ { whereValue: Dictionary): T[]; /** - * Returns everything but the last entry of the array. Especially useful on the arguments object. - * Pass n to exclude the last n elements from the result. - * @param array Retreive all elements except the last `n`. + * Gets all but the last element or last n elements of an array. If a callback is provided + * elements at the end of the array are excluded from the result as long as the callback + * returns truey. The callback is bound to thisArg and invoked with three arguments; + * (value, index, array). + * + * 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 array The array to query. * @param n Leaves this many elements behind, optional. * @return Returns everything but the last `n` elements of `array`. **/ + export function initial( + array: List): T[]; + + /** + * @see _.initial + * @param n The number of elements to exclude. + **/ export function initial( array: List, - n?: number): T[]; + n: number): T[]; + + /** + * @see _.initial + * @param callback The function called per element + **/ + export function initial( + array: List, + callback: ListIterator): T[]; + + /** + * @see _.initial + * @param pluckValue _.pluck style callback + **/ + export function initial( + array: List, + pluckValue: string): T[]; + + /** + * @see _.initial + * @param whereValue _.where style callback + **/ + export function initial( + array: List, + whereValue: Dictionary): T[]; /** * Returns the last element of an array. Passing n will return the last n elements of the array.