UNPKG

ut2

Version:

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

27 lines (23 loc) 873 B
'use strict'; var eq = require('./eq.js'); var identity = require('./identity.js'); var createIteratee = require('./internals/createIteratee.js'); var isArray = require('./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; }); } module.exports = intersection;