Fixes contains searching keys instead of values on objects, also adds "includes" alias.

This commit is contained in:
Daniel Beckwith
2015-07-07 17:49:06 -04:00
parent 304a251979
commit 2f7754dceb
2 changed files with 42 additions and 5 deletions
+7 -2
View File
@@ -363,14 +363,19 @@ result = <string[]>_.at(['moe', 'larry', 'curly'], 0, 2);
result = <boolean>_.contains([1, 2, 3], 1);
result = <boolean>_.contains([1, 2, 3], 1, 2);
result = <boolean>_.contains({ 'name': 'moe', 'age': 40 }, 'moe');
result = <boolean>_.contains({ 'moe': 30, 'larry': 40, 'curly': 67 }, 40);
result = <boolean>_.contains('curly', 'ur');
result = <boolean>_.include([1, 2, 3], 1);
result = <boolean>_.include([1, 2, 3], 1, 2);
result = <boolean>_.include({ 'name': 'moe', 'age': 40 }, 'moe');
result = <boolean>_.include({ 'moe': 30, 'larry': 40, 'curly': 67 }, 40);
result = <boolean>_.include('curly', 'ur');
result = <boolean>_.includes([1, 2, 3], 1);
result = <boolean>_.includes([1, 2, 3], 1, 2);
result = <boolean>_.includes({ 'moe': 30, 'larry': 40, 'curly': 67 }, 40);
result = <boolean>_.includes('curly', 'ur');
result = <_.Dictionary<number>>_.countBy([4.3, 6.1, 6.4], function (num) { return Math.floor(num); });
result = <_.Dictionary<number>>_.countBy([4.3, 6.1, 6.4], function (num) { return this.floor(num); }, Math);
result = <_.Dictionary<number>>_.countBy(['one', 'two', 'three'], 'length');
+35 -3
View File
@@ -2198,11 +2198,11 @@ declare module _ {
/**
* @see _.contains
* @param dictionary The dictionary to iterate over.
* @param key The key in the dictionary to search for.
* @param value The value in the dictionary to search for.
**/
contains<T>(
dictionary: Dictionary<T>,
key: string,
value: T,
fromIndex?: number): boolean;
/**
@@ -2236,7 +2236,7 @@ declare module _ {
**/
include<T>(
dictionary: Dictionary<T>,
key: string,
value: T,
fromIndex?: number): boolean;
/**
@@ -2246,6 +2246,38 @@ declare module _ {
searchString: string,
targetString: string,
fromIndex?: number): boolean;
/**
* @see _.contains
**/
includes<T>(
collection: Array<T>,
target: T,
fromIndex?: number): boolean;
/**
* @see _.contains
**/
includes<T>(
collection: List<T>,
target: T,
fromIndex?: number): boolean;
/**
* @see _.contains
**/
includes<T>(
dictionary: Dictionary<T>,
value: T,
fromIndex?: number): boolean;
/**
* @see _.contains
**/
includes(
searchString: string,
targetString: string,
fromIndex?: number): boolean;
}
//_.countBy