isSupersetOf

Returns a boolean indicating if all elements of the given set are in this set.

Info

The set can be either an Array or Set.

Note

Set options.proper to true to require a strict superset.

Venn Diagram

Related

Syntax

TypeScript
import { isSupersetOf } from '@opentf/std';
isSupersetOf(a: unknown[] | Set<unknown>, b: unknown[] | Set<unknown>, options?: { proper?: boolean }): boolean

Examples

TypeScript
const a = [1, 2, 3];

isSupersetOf(a, []) //=> true

isSupersetOf(a, [1]) //=> true

isSupersetOf(a, [1, 2]) //=> true

isSupersetOf(a, [1, 2, 3]) //=> true


const evens = new Set([2, 4, 6, 8, 10, 12, 14, 16, 18]);
const fours = new Set([4, 8, 12, 16]);

isSupersetOf(evens, fours) //=> true


const set1 = new Set([1, 2, 3]);
const set2 = new Set([1, 2, 3]);

isSupersetOf(set1, set2) //=> true


const a = [1, 2, 3, 4];

isSupersetOf(a, [1, 2, 3, 4, 5]) //=> false

const primes = new Set([2, 3, 5, 7, 11, 13, 17, 19]);
const odds = new Set([3, 5, 7, 9, 11, 13, 15, 17, 19]);

isSupersetOf(primes, odds) //=> false

const set3 = new Set([1, 2, 3, 4, 5]);

isSupersetOf(set1, set2, { proper: true }) //=> false

isSupersetOf(set3, set1, { proper: false }) //=> true

isSupersetOf(set3, set2, { proper: true }) //=> true

Try it

Last updated on
Edit this page