Added _.includes method. This closes #4610.

This commit is contained in:
Dave Allen
2015-06-10 12:19:26 -07:00
parent 52dc8fc393
commit 54d6e6fb6b
2 changed files with 50 additions and 8 deletions
+5
View File
@@ -371,6 +371,11 @@ result = <boolean>_.include([1, 2, 3], 1, 2);
result = <boolean>_.include({ 'name': 'moe', 'age': 40 }, 'moe');
result = <boolean>_.include('curly', 'ur');
result = <boolean>_.includes([1, 2, 3], 1);
result = <boolean>_.includes([1, 2, 3], 1, 2);
result = <boolean>_.includes({ 'name': 'moe', 'age': 40 }, 'moe');
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');
+45 -8
View File
@@ -2172,7 +2172,7 @@ declare module _ {
...indexes: number[]): T[];
}
//_.contains
//_.includes
interface LoDashStatic {
/**
* Checks if a given value is present in a collection using strict equality for comparisons,
@@ -2182,13 +2182,49 @@ declare module _ {
* @param fromIndex The index to search from.
* @return True if the target element is found, else false.
**/
includes<T>(
collection: Array<T>,
target: T,
fromIndex?: number): boolean;
/**
* @see _.includes
**/
includes<T>(
collection: List<T>,
target: T,
fromIndex?: number): boolean;
/**
* @see _.includes
* @param dictionary The dictionary to iterate over.
* @param key The key in the dictionary to search for.
**/
includes<T>(
dictionary: Dictionary<T>,
key: string,
fromIndex?: number): boolean;
/**
* @see _.includes
* @param searchString the string to search
* @param targetString the string to search for
**/
includes(
searchString: string,
targetString: string,
fromIndex?: number): boolean;
/**
* @see _.includes
**/
contains<T>(
collection: Array<T>,
target: T,
fromIndex?: number): boolean;
/**
* @see _.contains
* @see _.includes
**/
contains<T>(
collection: List<T>,
@@ -2196,7 +2232,7 @@ declare module _ {
fromIndex?: number): boolean;
/**
* @see _.contains
* @see _.includes
* @param dictionary The dictionary to iterate over.
* @param key The key in the dictionary to search for.
**/
@@ -2206,7 +2242,7 @@ declare module _ {
fromIndex?: number): boolean;
/**
* @see _.contains
* @see _.includes
* @param searchString the string to search
* @param targetString the string to search for
**/
@@ -2215,8 +2251,9 @@ declare module _ {
targetString: string,
fromIndex?: number): boolean;
/**
* @see _.contains
* @see _.includes
**/
include<T>(
collection: Array<T>,
@@ -2224,7 +2261,7 @@ declare module _ {
fromIndex?: number): boolean;
/**
* @see _.contains
* @see _.includes
**/
include<T>(
collection: List<T>,
@@ -2232,7 +2269,7 @@ declare module _ {
fromIndex?: number): boolean;
/**
* @see _.contains
* @see _.includes
**/
include<T>(
dictionary: Dictionary<T>,
@@ -2240,7 +2277,7 @@ declare module _ {
fromIndex?: number): boolean;
/**
* @see _.contains
* @see _.includes
**/
include(
searchString: string,