Path: blob/master/node_modules/@hapi/hoek/lib/intersect.js
1126 views
'use strict';12const internals = {};345module.exports = function (array1, array2, options = {}) {67if (!array1 ||8!array2) {910return (options.first ? null : []);11}1213const common = [];14const hash = (Array.isArray(array1) ? new Set(array1) : array1);15const found = new Set();16for (const value of array2) {17if (internals.has(hash, value) &&18!found.has(value)) {1920if (options.first) {21return value;22}2324common.push(value);25found.add(value);26}27}2829return (options.first ? null : common);30};313233internals.has = function (ref, key) {3435if (typeof ref.has === 'function') {36return ref.has(key);37}3839return ref[key] !== undefined;40};414243