Skip to content

Commit

Permalink
fix: randomizeArray with empty input returns copy now too
Browse files Browse the repository at this point in the history
  • Loading branch information
Sv443 committed Feb 11, 2024
1 parent 5038967 commit 17a6ad5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/cuddly-geckos-battle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sv443-network/userutils": patch
---

`randomizeArray` now returns a copy if an empty array is passed as well
2 changes: 1 addition & 1 deletion lib/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function randomizeArray<TItem = unknown>(array: TItem[]) {
const retArray = [...array]; // so array and retArray don't point to the same memory address

if(array.length === 0)
return array;
return retArray;

// shamelessly stolen from https://javascript.info/task/shuffle
for(let i = retArray.length - 1; i > 0; i--) {
Expand Down

0 comments on commit 17a6ad5

Please sign in to comment.