mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-03 16:47:49 +00:00
Move internal modules to “internal” folder.
This commit is contained in:
66
.internal/baseDifference.js
Normal file
66
.internal/baseDifference.js
Normal file
@@ -0,0 +1,66 @@
|
||||
import SetCache from './.internal/SetCache.js';
|
||||
import arrayIncludes from './.internal/arrayIncludes.js';
|
||||
import arrayIncludesWith from './.internal/arrayIncludesWith.js';
|
||||
import arrayMap from './.internal/arrayMap.js';
|
||||
import cacheHas from './.internal/cacheHas.js';
|
||||
|
||||
/** Used as the size to enable large array optimizations. */
|
||||
const LARGE_ARRAY_SIZE = 200;
|
||||
|
||||
/**
|
||||
* The base implementation of methods like `difference` without support
|
||||
* for excluding multiple arrays.
|
||||
*
|
||||
* @private
|
||||
* @param {Array} array The array to inspect.
|
||||
* @param {Array} values The values to exclude.
|
||||
* @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.
|
||||
*/
|
||||
function baseDifference(array, values, iteratee, comparator) {
|
||||
let index = -1;
|
||||
let includes = arrayIncludes;
|
||||
let isCommon = true;
|
||||
const length = array.length;
|
||||
const result = [];
|
||||
const valuesLength = values.length;
|
||||
|
||||
if (!length) {
|
||||
return result;
|
||||
}
|
||||
if (iteratee) {
|
||||
values = arrayMap(values, value => iteratee(value));
|
||||
}
|
||||
if (comparator) {
|
||||
includes = arrayIncludesWith;
|
||||
isCommon = false;
|
||||
}
|
||||
else if (values.length >= LARGE_ARRAY_SIZE) {
|
||||
includes = cacheHas;
|
||||
isCommon = false;
|
||||
values = new SetCache(values);
|
||||
}
|
||||
outer:
|
||||
while (++index < length) {
|
||||
let value = array[index];
|
||||
const computed = iteratee == null ? value : iteratee(value);
|
||||
|
||||
value = (comparator || value !== 0) ? value : 0;
|
||||
if (isCommon && computed === computed) {
|
||||
let valuesIndex = valuesLength;
|
||||
while (valuesIndex--) {
|
||||
if (values[valuesIndex] === computed) {
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
result.push(value);
|
||||
}
|
||||
else if (!includes(values, computed, comparator)) {
|
||||
result.push(value);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export default baseDifference;
|
||||
Reference in New Issue
Block a user