summaryrefslogtreecommitdiff
path: root/src/util.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.js')
-rw-r--r--src/util.js10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/util.js b/src/util.js
index ecae45e..f83039f 100644
--- a/src/util.js
+++ b/src/util.js
@@ -50,3 +50,13 @@ export function apply(f, n, x0) {
return f(apply(f, n-1, x0));
}
}
+
+
+export function shuffle(arr) {
+ const shuffled = [...arr];
+ for (let i=arr.length-1; i > 0; i--) {
+ const j = Math.floor(Math.random() * (i+1));
+ [shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]]
+ }
+ return shuffled;
+}