1 var baseIndexOf = require('./internal/baseIndexOf'),
2 isArrayLike = require('./isArrayLike'),
3 isString = require('./isString'),
4 toInteger = require('./toInteger'),
5 values = require('./values');
7 /* Built-in method references for those with the same name as other `lodash` methods. */
8 var nativeMax = Math.max;
11 * Checks if `value` is in `collection`. If `collection` is a string it's checked
12 * for a substring of `value`, otherwise [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
13 * is used for equality comparisons. If `fromIndex` is negative, it's used as
14 * the offset from the end of `collection`.
18 * @category Collection
19 * @param {Array|Object|string} collection The collection to search.
20 * @param {*} value The value to search for.
21 * @param {number} [fromIndex=0] The index to search from.
22 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.reduce`.
23 * @returns {boolean} Returns `true` if `value` is found, else `false`.
26 * _.includes([1, 2, 3], 1);
29 * _.includes([1, 2, 3], 1, 2);
32 * _.includes({ 'user': 'fred', 'age': 40 }, 'fred');
35 * _.includes('pebbles', 'eb');
38 function includes(collection, value, fromIndex, guard) {
39 collection = isArrayLike(collection) ? collection : values(collection);
40 fromIndex = (fromIndex && !guard) ? toInteger(fromIndex) : 0;
42 var length = collection.length;
44 fromIndex = nativeMax(length + fromIndex, 0);
46 return isString(collection)
47 ? (fromIndex <= length && collection.indexOf(value, fromIndex) > -1)
48 : (!!length && baseIndexOf(collection, value, fromIndex) > -1);
51 module.exports = includes;