We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 11c76c0 commit 3e4f801Copy full SHA for 3e4f801
Array/Shuffle.js
@@ -0,0 +1,15 @@
1
+function shuffle(arr = []) {
2
+ const copy = arr.slice();
3
+
4
+ let currentIndex = arr.length;
5
+ let randomIndex;
6
+ while (currentIndex) {
7
+ randomIndex = Math.floor(Math.random() * currentIndex);
8
+ currentIndex--;
9
10
+ [copy[currentIndex], copy[randomIndex]] = [
11
+ copy[randomIndex], copy[currentIndex]];
12
+ };
13
14
+ return copy;
15
+};
0 commit comments