shuffle copied array (#9847)

This commit is contained in:
✨ Audrey ✨ 2024-06-26 15:41:02 -04:00 committed by GitHub
parent 89a34a396c
commit a3514001c0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 4 deletions

View File

@ -31,9 +31,9 @@ export class CryptoServiceRandomizer implements Randomizer {
async shuffle<T>(items: Array<T>, options?: { copy?: boolean }) {
const shuffled = options?.copy ?? true ? [...items] : items;
for (let i = items.length - 1; i > 0; i--) {
for (let i = shuffled.length - 1; i > 0; i--) {
const j = await this.uniform(0, i);
[items[i], items[j]] = [items[j], items[i]];
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
}
return shuffled;

View File

@ -31,9 +31,9 @@ export class CryptoServiceRandomizer implements Randomizer {
async shuffle<T>(items: Array<T>, options?: { copy?: boolean }) {
const shuffled = options?.copy ?? true ? [...items] : items;
for (let i = items.length - 1; i > 0; i--) {
for (let i = shuffled.length - 1; i > 0; i--) {
const j = await this.uniform(0, i);
[items[i], items[j]] = [items[j], items[i]];
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
}
return shuffled;