-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cfb1e31
commit 6694b92
Showing
1 changed file
with
11 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
// function to randomly shuffle an array | ||
export function shuffle(array: any[]):any[] { | ||
let arraycopy: any[]= []; | ||
array.forEach((val: any) => arraycopy.push(Object.assign({}, val))); | ||
for (let i = arraycopy.length - 1; i > 0; i--) { | ||
let j = Math.floor(Math.random() * (i + 1)); | ||
let temp:any = arraycopy[i]; | ||
arraycopy[i] = arraycopy[j]; | ||
arraycopy[j] = temp; | ||
} | ||
return arraycopy; | ||
} | ||
export function shuffle(array: any[]): any[] { | ||
let arraycopy: any[] = []; | ||
array.forEach((val: any) => arraycopy.push(Object.assign({}, val))); | ||
for (let i = arraycopy.length - 1; i > 0; i--) { | ||
let j = Math.floor(Math.random() * (i + 1)); | ||
let temp: any = arraycopy[i]; | ||
arraycopy[i] = arraycopy[j]; | ||
arraycopy[j] = temp; | ||
} | ||
return arraycopy; | ||
} |