MCPcopy Create free account
hub / github.com/cn-docs/vueuse / useArrayDifference

Function useArrayDifference

packages/shared/useArrayDifference/index.ts:37–60  ·  view source on GitHub ↗
(...args: any[])

Source from the content-addressed store, hash-verified

35 * @param args
36 */
37export function useArrayDifference<T>(...args: any[]): ComputedRef<T[]> {
38 const list: MaybeRefOrGetter<T[]> = args[0]
39 const values: MaybeRefOrGetter<T[]> = args[1]
40
41 let compareFn = args[2] ?? defaultComparator
42 const {
43 symmetric = false,
44 } = args[3] ?? {}
45
46 if (typeof compareFn === 'string') {
47 const key = compareFn as keyof T
48 compareFn = (value: T, othVal: T) => value[key] === othVal[key]
49 }
50
51 const diff1 = computed(() => toValue(list).filter(x => toValue(values).findIndex(y => compareFn(x, y)) === -1))
52
53 if (symmetric) {
54 const diff2 = computed(() => toValue(values).filter(x => toValue(list).findIndex(y => compareFn(x, y)) === -1))
55 return computed(() => symmetric ? [...toValue(diff1), ...toValue(diff2)] : toValue(diff1))
56 }
57 else {
58 return diff1
59 }
60}

Callers 1

index.test.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected