Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "array/difference"

Index

Type aliases

Functions

Type aliases

TSubstraction

TSubstraction: any[] | Set<any>

Difference Substraction Type

Functions

difference

  • difference<T>(base: T[], substraction: TSubstraction, allDiff?: boolean): T[]
  • difference<T>(base: Set<T>, substraction: TSubstraction, allDiff?: boolean): Set<T>
  • Gets the difference of the two arrays or sets


    Example:

    import { difference } from "@thalesrc/js-utils/array";
    
    const base = ["a", "b", "c", "d", "a", "b", "c", "d"];
    
    difference(base, ["a", "b"]); // ["c", "d", "c", "d"]
    difference(base, ["a", "b"], true); // ["c", "d", "a", "b", "c", "d"]

    Array Prototype Example:

    import "@thalesrc/js-utils/array/proto/difference";
    
    const base = ["a", "b", "c", "d", "a", "b", "c", "d"];
    
    base.difference(["a", "b"]); // ["c", "d", "c", "d"]

    Set Prototype Example:

    import "@thalesrc/js-utils/set/proto/difference";
    
    const base = new Set(["a", "b", "c", "d"]);
    
    base.difference(["a", "b"]); // Set(["c", "d"])

    Type parameters

    • T

    Parameters

    • base: T[]

      Base Set or Array

    • substraction: TSubstraction

      Set or Array to remove its values from the base

    • Optional allDiff: boolean

      By default all the same items encountered in substraction will be removed, set this argument as true to get real difference

    Returns T[]

    Difference of base from substraction

  • Type parameters

    • T

    Parameters

    • base: Set<T>
    • substraction: TSubstraction
    • Optional allDiff: boolean

    Returns Set<T>

Generated using TypeDoc