2019-05-11
描述
使用提供的对比函数对比两个数组中同一位置的元素是否相等,返回相等的元素列表。
提示
Array.prototype.findIndex()可以获取使用对比函数比对成功的索引值- 使用  
Array.prototype.filter()获取比对成功的索引值元素列表 
代码
const intersectionWith = (a, b, comp) => 
    a.filter(x => b.findIndex(y => comp(x, y)) !== -1);
示例
获取两个数组四舍五入后结果相同的原始元素:
intersectionWith([1, 1.2, 1.5, 3, 0], [1.9, 3, 0, 3.9], 
    (a, b) => Math.round(a) === Math.round(b)); // [1.5, 3, 0]
        
                
                ME!
            
                
                链滴