UNPKG

ut2

Version:

一个现代 JavaScript 实用工具库。[点击查看在线文档]。

25 lines (22 loc) 851 B
import eq from './eq.js'; import identity from './identity.js'; import createIteratee from './internals/createIteratee.js'; import isArray from './isArray.js'; function intersection(array, other, iteratee, strictCheck) { if (iteratee === void 0) { iteratee = identity; } if (strictCheck === void 0) { strictCheck = false; } if (!isArray(array) || !isArray(other)) { return []; } var internalIteratee = createIteratee(iteratee); var caches = []; return array.filter(function (item) { var current = internalIteratee(item); if (other.findIndex(function (value) { return eq(internalIteratee(value), current, strictCheck); }) !== -1 && !caches.includes(current)) { caches.push(current); return true; } return false; }); } export { intersection as default };