From 534102b6f0c2b3b37b65cdb8fe42a543c491bee4 Mon Sep 17 00:00:00 2001 From: Brian Zengel Date: Sun, 13 Oct 2013 19:33:20 -0400 Subject: [PATCH] definitions for _.last --- lodash/lodash-tests.ts | 11 +++++++++- lodash/lodash.d.ts | 49 +++++++++++++++++++++++++++++++++++------- 2 files changed, 51 insertions(+), 9 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 530259311..1dd39e5e2 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -115,6 +115,15 @@ result = _.initial(foodsType, { 'type': 'vegetable' }); result = _.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]); +result = _.last([1, 2, 3]); +result = _.last([1, 2, 3], 2); +result = _.last([1, 2, 3], function(num) { + return num > 1; +}); +result = _.last(foodsOrganic, 'organic'); +result = _.last(foodsType, { 'type': 'vegetable' }); + + //////////////////////////////////////////////////////////////////////////////////////// //WHAT'S LEFT //////////////////////////////////////////////////////////////////////////////////////// @@ -185,7 +194,7 @@ _.size({ one: 1, two: 2, three: 3 }); -_.last([5, 4, 3, 2, 1]); + diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index a5c5e5126..3985b9832 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -760,20 +760,53 @@ declare module _ { whereValue: Dictionary): T[]; /** - * Returns the last element of an array. Passing n will return the last n elements of the array. - * @param array Retrieves the last element of this array. - * @return Returns the last element of `array`. + * Gets the last element or last n elements of an array. If a callback is provided + * elements at the end of the array are returned 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. + * @return Returns the last element(s) of array. **/ export function last(array: List): T; /** * @see _.last - * @param n Return more than one element from `array`. + * @param n The number of elements to return **/ export function last( array: List, n: number): T[]; + /** + * @see _.last + * @param callback The function called per element + **/ + export function last( + array: List, + callback: ListIterator, + thisArg?: any): T[]; + + /** + * @see _.last + * @param pluckValue _.pluck style callback + **/ + export function last( + array: List, + pluckValue: string): T[]; + + /** + * @see _.last + * @param whereValue _.where style callback + **/ + export function last( + array: List, + whereValue: Dictionary): T[]; + /** * The opposite of _.initial this method gets all but the first element or first n elements of * an array. If a callback function is provided elements at the beginning of the array are excluded @@ -897,10 +930,10 @@ declare module _ { export function union(...arrays: List[]): T[]; /** - * Computes the list of values that are the intersection of all the arrays. Each value in the result - * is present in each of the arrays. - * @param arrays Array of arrays to compute the intersection of. - * @return The intersection of elements within `arrays`. + * Creates an array of unique values present in all provided arrays using strict + * equality for comparisons, i.e. ===. + * @param arrays The arrays to inspect. + * @return Returns an array of composite values. **/ export function intersection(...arrays: List[]): T[];