Skip to content

Commit 23ea2bf

Browse files
committed
fixed algorithm
1 parent 65aebfb commit 23ea2bf

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

shuffle.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import { rnd } from "./rnd.js";
22

3-
const shuffle = (array) => {
4-
for (let i = 0; i < array.length; i++) {
5-
const n = rnd(array.length);
6-
const tmp = array[i];
3+
export const shuffle = (array) => {
4+
for (let i = array.length - 1; i >= 1; i--) {
5+
const n = rnd(i + 1);
6+
const tmp = array[i];
77
array[i] = array[n];
88
array[n] = tmp;
99
}
1010
};
11-
12-
export { shuffle };

0 commit comments

Comments
 (0)