MCPcopy
hub / github.com/lodash/lodash / baseDifference

Function baseDifference

lodash.js:2811–2854  ·  view source on GitHub ↗

* The base implementation of methods like `_.difference` without support * for excluding multiple arrays or iteratee shorthands. * * @private * @param {Array} array The array to inspect. * @param {Array} values The values to exclude. * @param {Function} [iteratee] The i

(array, values, iteratee, comparator)

Source from the content-addressed store, hash-verified

2809 * @returns {Array} Returns the new array of filtered values.
2810 */
2811 function baseDifference(array, values, iteratee, comparator) {
2812 var index = -1,
2813 includes = arrayIncludes,
2814 isCommon = true,
2815 length = array.length,
2816 result = [],
2817 valuesLength = values.length;
2818
2819 if (!length) {
2820 return result;
2821 }
2822 if (iteratee) {
2823 values = arrayMap(values, baseUnary(iteratee));
2824 }
2825 if (comparator) {
2826 includes = arrayIncludesWith;
2827 isCommon = false;
2828 }
2829 else if (values.length >= LARGE_ARRAY_SIZE) {
2830 includes = cacheHas;
2831 isCommon = false;
2832 values = new SetCache(values);
2833 }
2834 outer:
2835 while (++index < length) {
2836 var value = array[index],
2837 computed = iteratee == null ? value : iteratee(value);
2838
2839 value = (comparator || value !== 0) ? value : 0;
2840 if (isCommon && computed === computed) {
2841 var valuesIndex = valuesLength;
2842 while (valuesIndex--) {
2843 if (values[valuesIndex] === computed) {
2844 continue outer;
2845 }
2846 }
2847 result.push(value);
2848 }
2849 else if (!includes(values, computed, comparator)) {
2850 result.push(value);
2851 }
2852 }
2853 return result;
2854 }
2855
2856 /**
2857 * The base implementation of `_.forEach` without support for iteratee shorthands.

Callers 2

baseXorFunction · 0.85
lodash.jsFile · 0.85

Calls 4

arrayMapFunction · 0.85
baseUnaryFunction · 0.85
includesFunction · 0.85
iterateeFunction · 0.70

Tested by

no test coverage detected