* 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 invo
(arrays, iteratee, comparator)
| 13761 | * @returns {Array} Returns the new array of shared values. |
| 13762 | */ |
| 13763 | function baseIntersection(arrays, iteratee, comparator) { |
| 13764 | var includes = comparator ? arrayIncludesWith : arrayIncludes, |
| 13765 | length = arrays[0].length, |
| 13766 | othLength = arrays.length, |
| 13767 | othIndex = othLength, |
| 13768 | caches = Array(othLength), |
| 13769 | maxLength = Infinity, |
| 13770 | result = []; |
| 13771 | |
| 13772 | while (othIndex--) { |
| 13773 | var array = arrays[othIndex]; |
| 13774 | if (othIndex && iteratee) { |
| 13775 | array = arrayMap(array, baseUnary(iteratee)); |
| 13776 | } |
| 13777 | maxLength = nativeMin(array.length, maxLength); |
| 13778 | caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120)) |
| 13779 | ? new SetCache(othIndex && array) |
| 13780 | : undefined; |
| 13781 | } |
| 13782 | array = arrays[0]; |
| 13783 | |
| 13784 | var index = -1, |
| 13785 | seen = caches[0]; |
| 13786 | |
| 13787 | outer: |
| 13788 | while (++index < length && result.length < maxLength) { |
| 13789 | var value = array[index], |
| 13790 | computed = iteratee ? iteratee(value) : value; |
| 13791 | |
| 13792 | value = (comparator || value !== 0) ? value : 0; |
| 13793 | if (!(seen |
| 13794 | ? cacheHas(seen, computed) |
| 13795 | : includes(result, computed, comparator) |
| 13796 | )) { |
| 13797 | othIndex = othLength; |
| 13798 | while (--othIndex) { |
| 13799 | var cache = caches[othIndex]; |
| 13800 | if (!(cache |
| 13801 | ? cacheHas(cache, computed) |
| 13802 | : includes(arrays[othIndex], computed, comparator)) |
| 13803 | ) { |
| 13804 | continue outer; |
| 13805 | } |
| 13806 | } |
| 13807 | if (seen) { |
| 13808 | seen.push(computed); |
| 13809 | } |
| 13810 | result.push(value); |
| 13811 | } |
| 13812 | } |
| 13813 | return result; |
| 13814 | } |
| 13815 | |
| 13816 | /** |
| 13817 | * The base implementation of `_.invert` and `_.invertBy` which inverts |