feat: non-destructive shuffle
This commit is contained in:
parent
18d83ff4d9
commit
50ec0801ed
|
@ -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) {
|
||||
|
|
|
@ -2,6 +2,7 @@ export {
|
|||
arrayUnique,
|
||||
flatten,
|
||||
fromObject as arrayFromObject,
|
||||
shuffle,
|
||||
shuffleInPlace
|
||||
} from './array';
|
||||
export {EventEmitterMixin as EventEmitter} from './event-emitter';
|
||||
|
|
Loading…
Reference in New Issue
Block a user