We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 423ee2c commit 00060dbCopy full SHA for 00060db
Sorts/RandomSort.js
@@ -0,0 +1,17 @@
1
+// Can be used to shuffle the items of an array.
2
+// This algorithm is called Fisher Yates Shuffle.
3
+
4
+export default RandomSort = function(arr) {
5
+ let n = arr.length;
6
7
+ for (let i = 0; i < n; i++) {
8
+ let j = Math.floor((i+1)*Math.random());
9
+ let shuffled_arr = arr;
10
11
+ let tmp = shuffled_arr[i];
12
+ shuffled_arr[i] = shuffled_arr[j];
13
+ shuffled_arr[j] = tmp;
14
+ }
15
16
+ return shuffled_arr;
17
+}
0 commit comments