10000 Document the Fisher-Yates algorithm in shuffle · immutable-js/immutable-js@27c28d8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 27c28d8

Browse files
committed
Document the Fisher-Yates algorithm in shuffle
1 parent 98c5923 commit 27c28d8

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/List.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,10 @@ export class List extends IndexedCollection {
142142

143143
shuffle(random = Math.random) {
144144
return this.withMutations((mutable) => {
145-
let current = mutable.size,
146-
destination,
147-
tmp;
145+
// implementation of the Fisher-Yates shuffle: https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
146+
let current = mutable.size;
147+
let destination;
148+
let tmp;
148149

149150
while (current) {
150151
destination = Math.floor(random() * current--);

0 commit comments

Comments
 (0)
0