Maths
isSupersetOf

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

The set can be either an Array or Set.

💡

The subset relationship can determined by passing boolean value to the proper param.

Venn Diagram

Related

Syntax

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

Examples

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, true) //=> false
 
isSupersetOf(set3, set1, false) //=> true
 
isSupersetOf(set3, set2, true) //=> true

Try