@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.
29 lines • 736 B
JavaScript
/**
* @module Collection
*/
/**
* @internal
*/
export class ShuffleIterable {
iterable;
mathRandom;
constructor(iterable, mathRandom) {
this.iterable = iterable;
this.mathRandom = mathRandom;
}
*[Symbol.iterator]() {
const newArray = [...this.iterable];
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=shuffle-iterable.js.map