* The base implementation of methods like `_.intersection`, without support * for iteratee shorthands, that accepts an array of arrays to inspect. * * @private * @param {Array} arrays The arrays to inspect. * @param {Function} [iteratee] The iteratee invoked per element.
(arrays, iteratee, comparator)
| 3177 | * @returns {Array} Returns the new array of shared values. |
| 3178 | */ |
| 3179 | function baseIntersection(arrays, iteratee, comparator) { |
| 3180 | var includes = comparator ? arrayIncludesWith : arrayIncludes, |
| 3181 | length = arrays[0].length, |
| 3182 | othLength = arrays.length, |
| 3183 | othIndex = othLength, |
| 3184 | caches = Array(othLength), |
| 3185 | maxLength = Infinity, |
| 3186 | result = []; |
| 3187 | |
| 3188 | while (othIndex--) { |
| 3189 | var array = arrays[othIndex]; |
| 3190 | if (othIndex && iteratee) { |
| 3191 | array = arrayMap(array, baseUnary(iteratee)); |
| 3192 | } |
| 3193 | maxLength = nativeMin(array.length, maxLength); |
| 3194 | caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120)) |
| 3195 | ? new SetCache(othIndex && array) |
| 3196 | : undefined; |
| 3197 | } |
| 3198 | array = arrays[0]; |
| 3199 | |
| 3200 | var index = -1, |
| 3201 | seen = caches[0]; |
| 3202 | |
| 3203 | outer: |
| 3204 | while (++index < length && result.length < maxLength) { |
| 3205 | var value = array[index], |
| 3206 | computed = iteratee ? iteratee(value) : value; |
| 3207 | |
| 3208 | value = (comparator || value !== 0) ? value : 0; |
| 3209 | if (!(seen |
| 3210 | ? cacheHas(seen, computed) |
| 3211 | : includes(result, computed, comparator) |
| 3212 | )) { |
| 3213 | othIndex = othLength; |
| 3214 | while (--othIndex) { |
| 3215 | var cache = caches[othIndex]; |
| 3216 | if (!(cache |
| 3217 | ? cacheHas(cache, computed) |
| 3218 | : includes(arrays[othIndex], computed, comparator)) |
| 3219 | ) { |
| 3220 | continue outer; |
| 3221 | } |
| 3222 | } |
| 3223 | if (seen) { |
| 3224 | seen.push(computed); |
| 3225 | } |
| 3226 | result.push(value); |
| 3227 | } |
| 3228 | } |
| 3229 | return result; |
| 3230 | } |
| 3231 | |
| 3232 | /** |
| 3233 | * The base implementation of `_.invert` and `_.invertBy` which inverts |