feat: non-destructive shuffle

This commit is contained in:
cha0s 2020-05-26 03:20:34 -05:00
parent 18d83ff4d9
commit 50ec0801ed
2 changed files with 7 additions and 0 deletions

View File

@ -14,6 +14,12 @@ export function fromObject(object) {
return array;
}
export function shuffle(array) {
const shuffled = [...array];
shuffleInPlace(shuffled);
return shuffled;
}
export function shuffleInPlace(array) {
let i = 0, j = 0, temp = null;
for (i = array.length - 1; i > 0; i -= 1) {

View File

@ -2,6 +2,7 @@ export {
arrayUnique,
flatten,
fromObject as arrayFromObject,
shuffle,
shuffleInPlace
} from './array';
export {EventEmitterMixin as EventEmitter} from './event-emitter';