mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-05 01:17:50 +00:00
Bump to v3.0.0.
This commit is contained in:
52
internal/baseDifference.js
Normal file
52
internal/baseDifference.js
Normal file
@@ -0,0 +1,52 @@
|
||||
import baseIndexOf from './baseIndexOf';
|
||||
import cacheIndexOf from './cacheIndexOf';
|
||||
import createCache from './createCache';
|
||||
|
||||
/**
|
||||
* The base implementation of `_.difference` which accepts a single array
|
||||
* of values to exclude.
|
||||
*
|
||||
* @private
|
||||
* @param {Array} array The array to inspect.
|
||||
* @param {Array} values The values to exclude.
|
||||
* @returns {Array} Returns the new array of filtered values.
|
||||
*/
|
||||
function baseDifference(array, values) {
|
||||
var length = array ? array.length : 0,
|
||||
result = [];
|
||||
|
||||
if (!length) {
|
||||
return result;
|
||||
}
|
||||
var index = -1,
|
||||
indexOf = baseIndexOf,
|
||||
isCommon = true,
|
||||
cache = isCommon && values.length >= 200 && createCache(values),
|
||||
valuesLength = values.length;
|
||||
|
||||
if (cache) {
|
||||
indexOf = cacheIndexOf;
|
||||
isCommon = false;
|
||||
values = cache;
|
||||
}
|
||||
outer:
|
||||
while (++index < length) {
|
||||
var value = array[index];
|
||||
|
||||
if (isCommon && value === value) {
|
||||
var valuesIndex = valuesLength;
|
||||
while (valuesIndex--) {
|
||||
if (values[valuesIndex] === value) {
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
result.push(value);
|
||||
}
|
||||
else if (indexOf(values, value) < 0) {
|
||||
result.push(value);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export default baseDifference;
|
||||
Reference in New Issue
Block a user