Skip to content

Commit

Permalink
Move shuffleEffects to utils.js
Browse files Browse the repository at this point in the history
  • Loading branch information
jolaleye committed Apr 27, 2019
1 parent 479f141 commit 43982e2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
23 changes: 1 addition & 22 deletions assets/effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,4 @@ for (const filename of effectList) {
components[name] = component;
}

function shuffleEffects() {
const copy = Object.entries(effects).slice(0);
const length = copy.length;

let index = -1;
let lastIndex = length - 1;
while (++index < length) {
const randomIndex = index + Math.floor(Math.random() * (lastIndex - index + 1));
const value = copy[randomIndex];
copy[randomIndex] = copy[index];
copy[index] = value;
}

const newEffects = {};
for (const effect of copy) {
newEffects[effect[0]] = effect[1];
}

return newEffects;
}

export { effects, components, shuffleEffects };
export { effects, components };
20 changes: 20 additions & 0 deletions assets/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export function shuffleEffects(obj) {
const copy = Object.entries(obj).slice(0);
const length = copy.length;

let index = -1;
let lastIndex = length - 1;
while (++index < length) {
const randomIndex = index + Math.floor(Math.random() * (lastIndex - index + 1));
const value = copy[randomIndex];
copy[randomIndex] = copy[index];
copy[index] = value;
}

const newEffects = {};
for (const effect of copy) {
newEffects[effect[0]] = effect[1];
}

return newEffects;
}

0 comments on commit 43982e2

Please sign in to comment.