我想执行设置差异操作。 例如。
var a = ['a', 'b'], tw = ['b', 'c'], cn = ['a', 'b']
var zz = a - tw // => zz should be `['a']`
var zz = a - cn // => zz should be `[]`
答案 0 :(得分:3)
尝试
let a = new Set(['a', 'b']);
let tw = new Set(['b', 'c']);
let cn = new Set(['a', 'b'])
let diff1 = new Set([...a].filter(x => !tw.has(x)));
let diff2 = new Set([...a].filter(x => !cn.has(x)));
使用下划线,
_(['a', 'b']).difference(['b', 'c']);
_(['a', 'b']).difference(['a', 'b']);