isSubsetOf
Returns a boolean indicating if all elements of this set are in the given set.
Info
The set can be either an Array or Set.
Note
Set options.proper to true to require a strict subset.
Venn Diagram
Syntax
TypeScript
import { isSubsetOf } from '@opentf/std'; isSubsetOf(a: unknown[] | Set<unknown>, b: unknown[] | Set<unknown>, options?: { proper?: boolean }): boolean
Examples
TypeScript
const a = [1, 2, 3]; isSubsetOf([], a) //=> true isSubsetOf([1], a) //=> true isSubsetOf([1, 2], a) //=> true isSubsetOf([1, 2, 3], a) //=> true const fours = new Set([4, 8, 12, 16]); const evens = new Set([2, 4, 6, 8, 10, 12, 14, 16, 18]); isSubsetOf(fours, evens) //=> true isSubsetOf([1, 2, 3, 4, 5], a) //=> 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]); isSubsetOf(primes, odds) //=> false const set1 = new Set([1, 2, 3]); const set2 = new Set([1, 2, 3]); const set3 = new Set([1, 2]); isSubsetOf(set1, set2) //=> true isSubsetOf(set1, set2, { proper: false }) //=> true isSubsetOf(set1, set2, { proper: true }) //=> false isSubsetOf(set1, set3, { proper: true }) //=> true