Skip to content

Commit cb03937

Browse files
committed
add fisher yates
1 parent 40b3b1b commit cb03937

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

shuffling/fisheryates/fisherYates.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export function fisherYates(arr: Array<number>): void {
2+
// for i from n−1 downto 1 do
3+
for(let i = arr.length - 1; i > 0; i++){
4+
const j = Math.floor(Math.random()* i );
5+
const temp = arr[j];
6+
arr[j] = arr[i];
7+
arr[i] = temp;
8+
}
9+
}

0 commit comments

Comments
 (0)