Skip to main content
Module

x/structurae/sorted-array.ts>SortedArray.getDifference

Data structures for high-performance JavaScript applications.
Latest
method SortedArray.getDifference
import { SortedArray } from "https://deno.land/x/structurae@4.0.1/sorted-array.ts";

Returns the difference of two sorted arrays, i.e. elements present in the first array but not in the second array. If symmetric=true finds the symmetric difference of two arrays, that is, the elements that are absent in one or another array.

Examples

SortedArray.getDifference([1, 2, 3, 4, 8], [2, 4, 6, 7, 9]); //=> [ 1, 3, 8 ]

// symmetric difference of sorted arrays: SortedArray.getDifference(first, second, true); //=> [ 1, 3, 6, 7, 8, 9 ]

// difference using a custom comparator: const customComparator = (a, b) => (a > b ? -1 : a < b ? 1 : 0); SortedArray.getDifference([8, 4, 3, 2, 1], [9, 7, 6, 4, 2], false, customComparator); //=> [ 8, 3, 1 ]

Parameters

a: U

the first array

b: U

the second array

optional
symmetric = [UNSUPPORTED]
optional
comparator: Comparator<T> = [UNSUPPORTED]
optional
container: U = [UNSUPPORTED]

Returns

container

the difference of the arrays