Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "array/intersection"

Index

Type aliases

Functions

Type aliases

TInclusion

TInclusion: any[] | Set<any>

Intersection Inclusion Type

Functions

intersection

  • intersection<T>(base: T[], inclusion: TInclusion, allEquals?: boolean): T[]
  • intersection<T>(base: Set<T>, inclusion: TInclusion, allEquals?: boolean): Set<T>
  • Intersection

    Gets the intersection of the two arrays or sets


    Example:

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

    Array Prototype Example:

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

    Set Prototype Example:

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

    Type parameters

    • T

    Parameters

    • base: T[]

      Base Set or Array

    • inclusion: TInclusion

      Set or Array to include its values

    • Optional allEquals: boolean

      By default all the same items encountered in the inclusion will be included, set this argument as false to get real intersection

    Returns T[]

    Intersection of base and inclusion

  • Type parameters

    • T

    Parameters

    • base: Set<T>
    • inclusion: TInclusion
    • Optional allEquals: boolean

    Returns Set<T>

Generated using TypeDoc