diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 53e7a22b8..44cf8d387 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -302,11 +302,13 @@ result = _.map(stoogesAges, 'name'); result = _.max([4, 2, 8, 6]); result = _.max(stoogesAges, function(stooge) { return stooge.age; }); -result = _.max(stooges, 'age'); +result = _.max(stoogesAges, 'age'); result = _.min([4, 2, 8, 6]); result = _.min(stoogesAges, function(stooge) { return stooge.age; }); -result = _.min(stooges, 'age'); +result = _.min(stoogesAges, 'age'); + +result = _.pluck(stoogesAges, 'name'); result = _.reduce([1, 2, 3], function(sum, num) { return sum + num; @@ -336,6 +338,10 @@ result = _.reduceRight([[0, 1], [2, 3], [4, 5]], function(a, b) { return a. result = _.foldr([[0, 1], [2, 3], [4, 5]], function(a, b) { return a.concat(b); }, []); +result = _.reject([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); +result = _.reject(foodsCombined, 'organic'); +result = _.reject(foodsCombined, { 'type': 'fruit' }); + result = _.some([null, 0, 'yes', false], Boolean); result = _.some(foodsCombined, 'organic'); result = _.some(foodsCombined, { 'type': 'meat' }); @@ -358,27 +364,15 @@ _.where(listOfPlays, { author: "Shakespeare", year: 1611 }); var odds = _.reject([1, 2, 3, 4, 5, 6], (num) => num % 2 == 0); -_.invoke([[5, 1, 7], [3, 2, 1]], 'sort'); - -var stooges = [{ name: 'moe', age: 40 }, { name: 'larry', age: 50 }, { name: 'curly', age: 60 }]; -_.pluck(stooges, 'name'); - -_.max(stooges, (stooge) => stooge.age); - -_.max([1, 2, 3, 4, 5]); - -var numbers = [10, 5, 100, 2, 1000]; -_.min(numbers); - _.sortBy([1, 2, 3, 4, 5, 6], (num) => Math.sin(num)); -_.indexBy(stooges, 'age')['40'].age; -_(stooges).indexBy('age')['40'].name; -_(stooges) - .chain() - .indexBy('age') - .value()['40'].age; +// _.indexBy(stooges, 'age')['40'].age; +// _(stooges).indexBy('age')['40'].name; +// _(stooges) +// .chain() +// .indexBy('age') +// .value()['40'].age; _.shuffle([1, 2, 3, 4, 5, 6]); diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 33f33e416..a6b3d6fff 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -1416,6 +1416,16 @@ declare module _ { collection: Collection, whereValue: Dictionary): T; + /** + * Retrieves the value of a specified property from all elements in the collection. + * @param collection The collection to iterate over. + * @param property The property to pluck. + * @return A new array of property values. + **/ + export function pluck( + collection: Collection, + property: string): any[]; + /** * Reduces a collection to a value which is the accumulated result of running each * element in the collection through the callback, where each successive callback execution @@ -1467,14 +1477,49 @@ declare module _ { accumulator?: TResult, thisArg?: any): TResult; + /** + * @see _.reduceRight + **/ + export function foldr( + collection: Collection, + callback: MemoIterator, + accumulator?: TResult, + thisArg?: any): TResult; + /** - * @see _.reduceRight + * The opposite of _.filter this method returns the elements of a collection that + * the callback does not return truey for. + * + * 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 thisArg The this binding of callback. + * @return A new array of elements that failed the callback check. **/ - export function foldr( + export function reject( collection: Collection, - callback: MemoIterator, - accumulator?: TResult, - thisArg?: any): TResult; + callback: ListIterator, + thisArg?: any): T[]; + + /** + * @see _.reject + * @param pluckValue _.pluck style callback + **/ + export function reject( + collection: Collection, + pluckValue: string): T[]; + + /** + * @see _.reject + * @param whereValue _.where style callback + **/ + export function reject( + collection: Collection, + whereValue: Dictionary): T[]; /** * Checks if the callback returns a truey value for any element of a collection. The function @@ -1575,39 +1620,6 @@ declare module _ { list: Collection, properties: U): T[]; - /** - * Returns the values in list without the elements that the truth test (iterator) passes. - * The opposite of filter. - * Return all the elements for which a truth test fails. - * @param list Reject elements within this list. - * @param iterator Reject iterator function for each element in `list`. - * @param context `this` object in `iterator`, optional. - * @return The rejected list of elements. - **/ - export function reject( - list: Collection, - iterator: ListIterator, - context?: any): T[]; - - - - - - - - /** - * A convenient version of what is perhaps the most common use-case for map: extracting a list of - * property values. - * @param list The list to pluck elements out of that have the property `propertyName`. - * @param propertyName The property to look for on each element within `list`. - * @return The list of elements within `list` that have the property `propertyName`. - **/ - export function pluck( - list: Collection, - propertyName: string): T[]; - - - /** * Returns a sorted copy of list, ranked in ascending order by the results of running each value * through iterator. Iterator may also be the string name of the property to sort by (eg. length).