function fn(a, b) {
const result = [];
const map = a.reduce((obj, item) => {
obj[item] ? obj[item]++ : obj[item] = 1;
return obj;
}, {});
b.forEach(item => {
if (map[item] && map[item] > 0) {
result.push(item);
map[item]--
}
})
return result
}fn([1,1,2,3,4,2,5],[1,6,5,3,7,4,2,1,1,2,2,1,6]);
原文:https://www.cnblogs.com/jaolo/p/11281562.html