feat: non-destructive shuffle
This commit is contained in:
parent
18d83ff4d9
commit
50ec0801ed
|
@ -14,6 +14,12 @@ export function fromObject(object) {
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function shuffle(array) {
|
||||||
|
const shuffled = [...array];
|
||||||
|
shuffleInPlace(shuffled);
|
||||||
|
return shuffled;
|
||||||
|
}
|
||||||
|
|
||||||
export function shuffleInPlace(array) {
|
export function shuffleInPlace(array) {
|
||||||
let i = 0, j = 0, temp = null;
|
let i = 0, j = 0, temp = null;
|
||||||
for (i = array.length - 1; i > 0; i -= 1) {
|
for (i = array.length - 1; i > 0; i -= 1) {
|
||||||
|
|
|
@ -2,6 +2,7 @@ export {
|
||||||
arrayUnique,
|
arrayUnique,
|
||||||
flatten,
|
flatten,
|
||||||
fromObject as arrayFromObject,
|
fromObject as arrayFromObject,
|
||||||
|
shuffle,
|
||||||
shuffleInPlace
|
shuffleInPlace
|
||||||
} from './array';
|
} from './array';
|
||||||
export {EventEmitterMixin as EventEmitter} from './event-emitter';
|
export {EventEmitterMixin as EventEmitter} from './event-emitter';
|
||||||
|
|
Loading…
Reference in New Issue
Block a user