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

Info

It uses isEql for deep comparison of values.

Venn Diagram

Syntax

TypeScript
import { difference } from '@opentf/std';

difference(
  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

TypeScript
const odds = [1, 3, 5, 7, 9];
const squares = [1, 4, 9];
difference([odds, squares]); //=> [3, 5, 7]

const bucket1 = ["apple", "mango", "orange"]
const bucket2 = ["Mango", "Apple"]

difference([bucket1, bucket2], (f) => f.toLowerCase()); //=> ['orange']

difference([[{ a: 1 }, {a: 3}], [{ a: 1 }, { a: 2 }]]); //=> [{a: 3}]
Last updated on
Edit this page