Skip to content

Commit 9860ae2

Browse files
authored
Merge pull request #10 from abc516/abc516/fisher_yates
add fisher yates
2 parents 7755454 + da3ec0e commit 9860ae2

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

shuffling/fisheryates/fisherYates.ts

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

0 commit comments

Comments
 (0)