Array
diff

⚖️ Creates an array of values from the first array that are not present in the other arrays.

It uses isEql for deep comparison of values.

Venn Diagram

Syntax

import { diff } from '@opentf/std';
 
diff(
  collections: unknown[][] = [],
  by?: (val: unknown) => unknown
): unknown[]

Parameters

  • collections: An array of arrays to compare. The first array is the source.
  • by: An optional iteratee invoked for each element to generate the criterion by which difference is computed.

Returns

A new array of filtered values.

Examples

const odds = [1, 3, 5, 7, 9];
const squares = [1, 4, 9];
diff([odds, squares]); //=> [3, 5, 7]
 
const bucket1 = ["apple", "mango", "orange"]
const bucket2 = ["Mango", "Apple"]
 
diff([bucket1, bucket2], (f) => f.toLowerCase()); //=> ['orange']
 
diff([[{ a: 1 }, {a: 3}], [{ a: 1 }, { a: 2 }]]); //=> [{a: 3}]

Related

Try