Rename baseIncludes to arrayIncludes and includesWith to arrayIncludesWith.

This commit is contained in:
John-David Dalton
2015-11-08 19:43:36 -08:00
parent 9c44430975
commit 4f104d74ca

View File

@@ -481,6 +481,41 @@
return result; return result;
} }
/**
* A specialized version of `_.includes` for arrays without support for
* specifying an index to search from.
*
* @private
* @param {Array} array The array to search.
* @param {*} target The value to search for.
* @returns {boolean} Returns `true` if `target` is found, else `false`.
*/
function arrayIncludes(array, value) {
return !!array.length && baseIndexOf(array, value, 0) > -1;
}
/**
* A specialized version of `_.includesWith` for arrays without support for
* specifying an index to search from.
*
* @private
* @param {Array} array The array to search.
* @param {*} target The value to search for.
* @param {Function} comparator The comparator invoked per element.
* @returns {boolean} Returns `true` if `target` is found, else `false`.
*/
function arrayIncludesWith(array, value, comparator) {
var index = -1,
length = array.length;
while (++index < length) {
if (comparator(value, array[index])) {
return true;
}
}
return false;
}
/** /**
* A specialized version of `_.map` for arrays without support for callback * A specialized version of `_.map` for arrays without support for callback
* shorthands. * shorthands.
@@ -721,22 +756,6 @@
return -1; return -1;
} }
function baseIncludes(array, value) {
return baseIndexOf(array, value, 0) > -1;
}
function includesWith(array, value, comparator) {
var index = -1,
length = array ? array.length : 0;
while (++index < length) {
if (comparator(value, array[index])) {
return true;
}
}
return false;
}
/** /**
* The base implementation of `_.pairs` and `_.pairsIn` which creates an array * The base implementation of `_.pairs` and `_.pairsIn` which creates an array
* of key-value pairs for `object` corresponding to the property names of `props`. * of key-value pairs for `object` corresponding to the property names of `props`.
@@ -2309,12 +2328,13 @@
* @private * @private
* @param {Array} array The array to inspect. * @param {Array} array The array to inspect.
* @param {Array} values The values to exclude. * @param {Array} values The values to exclude.
* @param {Function} [iteratee] The function invoked per element. * @param {Function} [iteratee] The iteratee invoked per element.
* @param {Function} [comparator] The comparator invoked per element.
* @returns {Array} Returns the new array of filtered values. * @returns {Array} Returns the new array of filtered values.
*/ */
function baseDifference(array, values, iteratee, comparator) { function baseDifference(array, values, iteratee, comparator) {
var index = -1, var index = -1,
includes = baseIncludes, includes = arrayIncludes,
isCommon = true, isCommon = true,
length = array.length, length = array.length,
result = [], result = [],
@@ -2327,7 +2347,7 @@
values = arrayMap(values, baseUnary(iteratee)); values = arrayMap(values, baseUnary(iteratee));
} }
if (comparator) { if (comparator) {
includes = includesWith; includes = arrayIncludesWith;
isCommon = false; isCommon = false;
} }
else if (values.length >= LARGE_ARRAY_SIZE) { else if (values.length >= LARGE_ARRAY_SIZE) {
@@ -2603,11 +2623,12 @@
* *
* @private * @private
* @param {Array} arrays The arrays to inspect. * @param {Array} arrays The arrays to inspect.
* @param {Function} [iteratee] The function invoked per element. * @param {Function} [iteratee] The iteratee invoked per element.
* @param {Function} [comparator] The comparator invoked per element.
* @returns {Array} Returns the new array of shared values. * @returns {Array} Returns the new array of shared values.
*/ */
function baseIntersection(arrays, iteratee, comparator) { function baseIntersection(arrays, iteratee, comparator) {
var includes = comparator ? includesWith : baseIncludes, var includes = comparator ? arrayIncludesWith : arrayIncludes,
othLength = arrays.length, othLength = arrays.length,
othIndex = othLength, othIndex = othLength,
caches = Array(othLength), caches = Array(othLength),
@@ -3342,13 +3363,14 @@
* *
* @private * @private
* @param {Array} array The array to inspect. * @param {Array} array The array to inspect.
* @param {Function} [iteratee] The function invoked per element. * @param {Function} [iteratee] The iteratee invoked per element.
* @param {Function} [comparator] The comparator invoked per element.
* @returns {Array} Returns the new duplicate free array. * @returns {Array} Returns the new duplicate free array.
*/ */
function baseUniq(array, iteratee, comparator) { function baseUniq(array, iteratee, comparator) {
var seen, var seen,
index = -1, index = -1,
includes = baseIncludes, includes = arrayIncludes,
length = array.length, length = array.length,
isCommon = true, isCommon = true,
result = [], result = [],
@@ -3356,7 +3378,7 @@
if (comparator) { if (comparator) {
isCommon = false; isCommon = false;
includes = includesWith; includes = arrayIncludesWith;
} }
else if (length >= LARGE_ARRAY_SIZE) { else if (length >= LARGE_ARRAY_SIZE) {
isCommon = false; isCommon = false;