Set
Functions
addSetsToSet
▸ addSetsToSet<T
>(mainSet
, ...setsToAdd
): void
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
Name |
---|
T |
Parameters
Name | Type |
---|---|
mainSet | Set <T > |
...setsToAdd | readonly ReadonlySet <T >[] |
Returns
void
Defined in
packages/isaacscript-common/src/functions/set.ts:12
combineSets
▸ combineSets<T
>(...sets
): Set
<T
>
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
Name |
---|
T |
Parameters
Name | Type |
---|---|
...sets | readonly ReadonlySet <T >[] |
Returns
Set
<T
>
Defined in
packages/isaacscript-common/src/functions/set.ts:30
copySet
▸ copySet<T
>(oldSet
): Set
<T
>
Helper function to copy a set. (You can also use a Set constructor to accomplish this task.)
Type parameters
Name |
---|
T |
Parameters
Name | Type |
---|---|
oldSet | ReadonlySet <T > |
Returns
Set
<T
>
Defined in
packages/isaacscript-common/src/functions/set.ts:43
deleteSetsFromSet
▸ deleteSetsFromSet<T
>(mainSet
, ...setsToRemove
): void
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
Name |
---|
T |
Parameters
Name | Type |
---|---|
mainSet | Set <T > |
...setsToRemove | readonly ReadonlySet <T >[] |
Returns
void
Defined in
packages/isaacscript-common/src/functions/set.ts:58
getRandomSetElement
▸ getRandomSetElement<T
>(set
, seedOrRNG
, exceptions?
): T
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
Name | Type |
---|---|
T | extends string | number |
Parameters
Name | Type | Default value | Description |
---|---|---|---|
set | ReadonlySet <T > | undefined | The set to get an element from. |
seedOrRNG | undefined | 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 | readonly T [] | [] | Optional. An array of elements to skip over if selected. |
Returns
T
Defined in
packages/isaacscript-common/src/functions/set.ts:82
getSetCombinations
▸ getSetCombinations<T
>(set
, includeEmptyArray
): ReadonlyArray
<ReadonlySet
<T
>>
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
includeEmptyArray
is set to true) - [1]
- [2]
- [3]
- [1, 2]
- [1, 3]
- [2, 3]
- [1, 2, 3]
Type parameters
Name | Type |
---|---|
T | extends string | number |
Parameters
Name | Type | Description |
---|---|---|
set | ReadonlySet <T > | The set to get the combinations of. |
includeEmptyArray | boolean | Whether to include an empty array in the combinations. |
Returns
ReadonlyArray
<ReadonlySet
<T
>>
Defined in
packages/isaacscript-common/src/functions/set.ts:110
getSortedSetValues
▸ getSortedSetValues<T
>(set
): T
[]
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
Name | Type |
---|---|
T | extends string | number |
Parameters
Name | Type |
---|---|
set | ReadonlySet <T > |
Returns
T
[]
Defined in
packages/isaacscript-common/src/functions/set.ts:127
objectKeysToReadonlySet
▸ objectKeysToReadonlySet<K
, V
>(object
): ReadonlySet
<K
>
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
Name | Type |
---|---|
K | extends string | number | symbol |
V | V |
Parameters
Name | Type |
---|---|
object | Record <K , V > |
Returns
ReadonlySet
<K
>
Defined in
packages/isaacscript-common/src/functions/set.ts:156
objectKeysToSet
▸ objectKeysToSet<K
, V
>(object
): Set
<K
>
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
Name | Type |
---|---|
K | extends string | number | symbol |
V | V |
Parameters
Name | Type |
---|---|
object | Record <K , V > |
Returns
Set
<K
>
Defined in
packages/isaacscript-common/src/functions/set.ts:171
objectValuesToReadonlySet
▸ objectValuesToReadonlySet<K
, V
>(object
): ReadonlySet
<V
>
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
Name | Type |
---|---|
K | extends string | number | symbol |
V | V |
Parameters
Name | Type |
---|---|
object | Record <K , V > |
Returns
ReadonlySet
<V
>
Defined in
packages/isaacscript-common/src/functions/set.ts:191
objectValuesToSet
▸ objectValuesToSet<K
, V
>(object
): Set
<V
>
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
Name | Type |
---|---|
K | extends string | number | symbol |
V | V |
Parameters
Name | Type |
---|---|
object | Record <K , V > |
Returns
Set
<V
>
Defined in
packages/isaacscript-common/src/functions/set.ts:207
setAdd
▸ setAdd<T
>(set
, ...elements
): void
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
Name |
---|
T |
Parameters
Name | Type |
---|---|
set | Set <T > |
...elements | readonly T [] |
Returns
void
Defined in
packages/isaacscript-common/src/functions/set.ts:226
setHas
▸ setHas<T
>(set
, ...elements
): boolean
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
Name |
---|
T |
Parameters
Name | Type |
---|---|
set | ReadonlySet <T > |
...elements | readonly T [] |
Returns
boolean
Defined in
packages/isaacscript-common/src/functions/set.ts:239
sumSet
▸ sumSet(set
): number
Helper function to sum every value in a set together.
Parameters
Name | Type |
---|---|
set | ReadonlySet <number > |
Returns
number