Set
Functions
Section titled “Functions”addSetsToSet()
Section titled “addSetsToSet()”addSetsToSet<
T>(mainSet, …setsToAdd):void
Defined in: packages/isaacscript-common/src/functions/set.ts:12
Helper function to add all of the values in one set to another set. The first set passed will be modified in place.
This function is variadic, meaning that you can specify N sets to add to the first set.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”mainSet
Section titled “mainSet”Set<T>
setsToAdd
Section titled “setsToAdd”…readonly ReadonlySet<T>[]
Returns
Section titled “Returns”void
combineSets()
Section titled “combineSets()”combineSets<
T>(…sets):ReadonlySet<T>
Defined in: packages/isaacscript-common/src/functions/set.ts:29
Helper function to create a new set that is the composition of two or more sets.
This function is variadic, meaning that you can specify N sets.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”…readonly ReadonlySet<T>[]
Returns
Section titled “Returns”ReadonlySet<T>
copySet()
Section titled “copySet()”copySet<
T>(oldSet):ReadonlySet<T>
Defined in: packages/isaacscript-common/src/functions/set.ts:43
Helper function to copy a set. (You can also use a Set constructor to accomplish this task.)
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”oldSet
Section titled “oldSet”ReadonlySet<T>
Returns
Section titled “Returns”ReadonlySet<T>
deleteSetsFromSet()
Section titled “deleteSetsFromSet()”deleteSetsFromSet<
T>(mainSet, …setsToRemove):void
Defined in: packages/isaacscript-common/src/functions/set.ts:53
Helper function to delete all of the values in one set from another set. The first set passed will be modified in place.
This function is variadic, meaning that you can specify N sets to remove from the first set.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”mainSet
Section titled “mainSet”Set<T>
setsToRemove
Section titled “setsToRemove”…readonly ReadonlySet<T>[]
Returns
Section titled “Returns”void
getRandomSetElement()
Section titled “getRandomSetElement()”getRandomSetElement<
T>(set,seedOrRNG,exceptions?):T
Defined in: packages/isaacscript-common/src/functions/set.ts:77
Helper function to get a random element from the provided set.
If you want to get an unseeded element, you must explicitly pass undefined to the seedOrRNG
parameter.
Type Parameters
Section titled “Type Parameters”T extends string | number
Parameters
Section titled “Parameters”ReadonlySet<T>
The set to get an element from.
seedOrRNG
Section titled “seedOrRNG”RNG | Seed | undefined
The Seed or RNG object to use. If an RNG object is provided, the
RNG.Next method will be called. If undefined is provided, it will default to
a random seed.
exceptions?
Section titled “exceptions?”readonly T[] = []
Optional. An array of elements to skip over if selected.
Returns
Section titled “Returns”T
getSetCombinations()
Section titled “getSetCombinations()”getSetCombinations<
T>(set,includeEmptyArray): readonlyReadonlySet<T>[]
Defined in: packages/isaacscript-common/src/functions/set.ts:105
Helper function to get all possible combinations of the given set. This includes the combination of an empty set.
For example, if this function is provided a set containing 1, 2, and 3, then it will return an array containing the following sets:
- [] (if
includeEmptyArrayis set to true) - [1]
- [2]
- [3]
- [1, 2]
- [1, 3]
- [2, 3]
- [1, 2, 3]
Type Parameters
Section titled “Type Parameters”T extends string | number
Parameters
Section titled “Parameters”ReadonlySet<T>
The set to get the combinations of.
includeEmptyArray
Section titled “includeEmptyArray”boolean
Whether to include an empty array in the combinations.
Returns
Section titled “Returns”readonly ReadonlySet<T>[]
getSortedSetValues()
Section titled “getSortedSetValues()”getSortedSetValues<
T>(set):T[]
Defined in: packages/isaacscript-common/src/functions/set.ts:121
Helper function to get a sorted array based on the contents of a set.
Normally, set values are returned in insertion order, so use this function when the ordering of the contents is important.
Type Parameters
Section titled “Type Parameters”T extends string | number
Parameters
Section titled “Parameters”ReadonlySet<T>
Returns
Section titled “Returns”T[]
objectKeysToReadonlySet()
Section titled “objectKeysToReadonlySet()”objectKeysToReadonlySet<
K,V>(object):ReadonlySet<K>
Defined in: packages/isaacscript-common/src/functions/set.ts:151
Helper function to convert the keys of an object to a read-only set.
Note that the set values will be inserted in a random order, due to how pairs works under the
hood.
Also see the objectKeysToSet function.
Type Parameters
Section titled “Type Parameters”K extends string | number | symbol
V
Parameters
Section titled “Parameters”object
Section titled “object”Record<K, V>
Returns
Section titled “Returns”ReadonlySet<K>
objectKeysToSet()
Section titled “objectKeysToSet()”objectKeysToSet<
K,V>(object):Set<K>
Defined in: packages/isaacscript-common/src/functions/set.ts:165
Helper function to convert the keys of an object to a set.
Note that the set values will be inserted in a random order, due to how pairs works under the
hood.
Also see the objectKeysToReadonlySet function.
Type Parameters
Section titled “Type Parameters”K extends string | number | symbol
V
Parameters
Section titled “Parameters”object
Section titled “object”Record<K, V>
Returns
Section titled “Returns”Set<K>
objectValuesToReadonlySet()
Section titled “objectValuesToReadonlySet()”objectValuesToReadonlySet<
K,V>(object):ReadonlySet<V>
Defined in: packages/isaacscript-common/src/functions/set.ts:186
Helper function to convert the values of an object to a read-only set.
Note that the set values will be inserted in a random order, due to how pairs works under the
hood.
Also see the objectValuesToSet function.
Type Parameters
Section titled “Type Parameters”K extends string | number | symbol
V
Parameters
Section titled “Parameters”object
Section titled “object”Record<K, V>
Returns
Section titled “Returns”ReadonlySet<V>
objectValuesToSet()
Section titled “objectValuesToSet()”objectValuesToSet<
K,V>(object):Set<V>
Defined in: packages/isaacscript-common/src/functions/set.ts:201
Helper function to convert the values of an object to a set.
Note that the set values will be inserted in a random order, due to how pairs works under the
hood.
Also see the objectValuesToReadonlySet function.
Type Parameters
Section titled “Type Parameters”K extends string | number | symbol
V
Parameters
Section titled “Parameters”object
Section titled “object”Record<K, V>
Returns
Section titled “Returns”Set<V>
setAdd()
Section titled “setAdd()”setAdd<
T>(set, …elements):void
Defined in: packages/isaacscript-common/src/functions/set.ts:221
Helper function to add one or more elements to a set at once without having to repeatedly call
the Set.add method.
This function is variadic, meaning that you can pass as many things as you want to add.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”Set<T>
elements
Section titled “elements”…readonly T[]
Returns
Section titled “Returns”void
setHas()
Section titled “setHas()”setHas<
T>(set, …elements):boolean
Defined in: packages/isaacscript-common/src/functions/set.ts:234
Helper function to check for one or more elements in a set at once without having to repeatedly
call the Set.has method.
This function is variadic, meaning that you can pass as many things as you want to check for. It will return true if one or more elements are found.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”ReadonlySet<T>
elements
Section titled “elements”…readonly T[]
Returns
Section titled “Returns”boolean
sumSet()
Section titled “sumSet()”sumSet(
set):number
Defined in: packages/isaacscript-common/src/functions/set.ts:242
Helper function to sum every value in a set together.
Parameters
Section titled “Parameters”ReadonlySet<number>
Returns
Section titled “Returns”number
