isaacscript-common 30.5.0 → 30.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "30.5.0",
3
+ "version": "30.5.2",
4
4
  "description": "Helper functions and features for IsaacScript mods.",
5
5
  "keywords": [
6
6
  "isaac",
@@ -213,15 +213,13 @@ export function copyArray<T>(
213
213
  numElements?: int,
214
214
  ): T[] {
215
215
  if (numElements === undefined) {
216
- numElements = oldArray.length;
216
+ return [...oldArray];
217
217
  }
218
218
 
219
219
  const newArray: T[] = [];
220
220
  for (let i = 0; i < numElements; i++) {
221
- const oldElement = oldArray[i];
222
- if (oldElement !== undefined) {
223
- newArray.push(oldElement);
224
- }
221
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
222
+ newArray.push(oldArray[i]!);
225
223
  }
226
224
 
227
225
  return newArray;
@@ -342,9 +340,11 @@ export function getRandomArrayElement<T>(
342
340
  );
343
341
  }
344
342
 
345
- const arrayWithoutExceptions = arrayRemove(array, ...exceptions);
346
- const randomIndex = getRandomArrayIndex(arrayWithoutExceptions, seedOrRNG);
347
- const randomElement = arrayWithoutExceptions[randomIndex];
343
+ if (exceptions.length > 0) {
344
+ array = arrayRemove(array, ...exceptions);
345
+ }
346
+ const randomIndex = getRandomArrayIndex(array, seedOrRNG);
347
+ const randomElement = array[randomIndex];
348
348
  if (randomElement === undefined) {
349
349
  error(
350
350
  `Failed to get a random array element since the random index of ${randomIndex} was not valid.`,