_.contains/_.include definition

This commit is contained in:
Brian Zengel
2013-10-18 16:11:17 -04:00
parent 6473c9662e
commit 4eeaabe3d9
2 changed files with 67 additions and 17 deletions
+10
View File
@@ -205,6 +205,16 @@ result = <number[]>_.without([1, 2, 1, 0, 3, 1, 4], 0, 1);
result = <string[]>_.at(['a', 'b', 'c', 'd', 'e'], [0, 2, 4]);
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('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('curly', 'ur');
result = <boolean>_.every([true, 1, null, 'yes'], Boolean);
result = <boolean>_.every(stoogesAges, 'age');
result = <boolean>_.every(stoogesAges, { 'age': 50 });
+57 -17
View File
@@ -785,6 +785,62 @@ declare module _ {
collection: Collection<T>,
...indexes: number[]): T[];
/**
* Checks if a given value is present in a collection using strict equality for comparisons,
* i.e. ===. If fromIndex is negative, it is used as the offset from the end of the collection.
* @param collection The collection to iterate over.
* @param target The value to check for.
* @param fromIndex The index to search from.
* @return True if the target element is found, else false.
**/
export function contains<T>(
collection: Collection<T>,
target: T,
fromIndex?: number): boolean;
/**
* @see _.contains
* @param dictionary The dictionary to iterate over.
* @param key The key in the dictionary to search for.
**/
export function contains<T>(
dictionary: Dictionary<T>,
key: string,
fromIndex?: number): boolean;
/**
* @see _.contains
* @param searchString the string to search
* @param targetString the string to search for
**/
export function contains(
searchString: string,
targetString: string,
fromIndex?: number): boolean;
/**
* @see _.contains
**/
export function include<T>(
collection: Collection<T>,
target: T,
fromIndex?: number): boolean;
/**
* @see _.contains
**/
export function include<T>(
dictionary: Dictionary<T>,
key: string,
fromIndex?: number): boolean;
/**
* @see _.contains
**/
export function include(
searchString: string,
targetString: string,
fromIndex?: number): boolean;
/**
* Checks if the given callback returns truey value for all elements of a collection.
@@ -1176,23 +1232,7 @@ declare module _ {
/**
* Returns true if the value is present in the list. Uses indexOf internally,
* if list is an Array.
* @param list Checks each element to see if `value` is present.
* @param value The value to check for within `list`.
* @return True if `value` is present in `list`, otherwise false.
**/
export function contains<T>(
list: Collection<T>,
value: T): boolean;
/**
* @see _.contains
**/
export function include<T>(
list: Collection<T>,
value: T): boolean;
/**
* Calls the method named by methodName on each value in the list. Any extra arguments passed to