We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 65aebfb commit 23ea2bfCopy full SHA for 23ea2bf
1 file changed
shuffle.js
@@ -1,12 +1,10 @@
1
import { rnd } from "./rnd.js";
2
3
-const shuffle = (array) => {
4
- for (let i = 0; i < array.length; i++) {
5
- const n = rnd(array.length);
6
- const tmp = array[i];
+export const shuffle = (array) => {
+ for (let i = array.length - 1; i >= 1; i--) {
+ const n = rnd(i + 1);
+ const tmp = array[i];
7
array[i] = array[n];
8
array[n] = tmp;
9
}
10
};
11
-
12
-export { shuffle };
0 commit comments