We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4e635ab commit 1b0537dCopy full SHA for 1b0537d
functions.js
@@ -17,3 +17,17 @@ function randItem(items) {
17
function toPrecision(number, precision) {
18
return +((number).toFixed(precision));
19
}
20
+
21
+// shuffles items and returns a new array. Based on the modern Fisher-Yates shuffle algorithm
22
+function shuffleItems(items) {
23
+ return items.reduce((result, item, index) => {
24
+ if (index === items.length - 1) {
25
+ return result;
26
+ }
27
28
+ const jindex = Math.floor(Math.random() * (items.length - 1 - index + 1)) + index;
29
+ [result[index], result[jindex]] = [result[jindex], result[index]];
30
31
32
+ }, items);
33
+}
0 commit comments