UNPKG

@daiso-tech/core

Version:

The library offers flexible, framework-agnostic solutions for modern web applications, built on adaptable components that integrate seamlessly with popular frameworks like Next Js.

30 lines 856 B
/** * @module Collection */ import {} from "../../../../collection/contracts/_module-exports.js"; /** * @internal */ export class AsyncShuffleIterable { collection; mathRandom; constructor(collection, mathRandom) { this.collection = collection; this.mathRandom = mathRandom; } async *[Symbol.asyncIterator]() { const newArray = [...(await this.collection.toArray())]; for (let i = newArray.length - 1; i > 0; i--) { const j = Math.floor(this.mathRandom() * (i + 1)); const temp = newArray[i]; if (newArray[j] !== undefined) { newArray[i] = newArray[j]; } if (temp !== undefined) { newArray[j] = temp; } } yield* newArray; } } //# sourceMappingURL=async-shuffle-iterable.js.map