/**
 * 数组之间的差异结果对象结构接口
 * left 第一个数组独有的元素列表
 * right 第二个数组独有的元素列表
 * common 两个数组共有的元素列表。注意: 这里的元素实质上是从第一个集合获取的
 */ export interface ArrayDiff < L , R > { left : L [ ] ; right : R [ ] ; common : L [ ] ; } param left param right param kFn returns export function diffBy < L , R > ( left , right , kFn = ( v ) => v ) { const kThanSet = new Set ( left . map ( kFn ) ) ; const kThatSet = new Set ( right . map ( kFn ) ) ; const leftUnique = left . filter ( ( v , ... args ) => ! kThatSet . has ( kFn ( v , ... args ) ) ) ; const rightUnique = right . filter ( ( v , ... args ) => ! kThanSet . has ( kFn ( v , ... args ) ) ) ; const kLeftSet = new Set ( leftUnique . map ( kFn ) ) ; const common = left . filter ( ( v , ... args ) => ! kLeftSet . has ( kFn ( v , ... args ) ) ) ; return { left : leftUnique , right : rightUnique , common } ; }