diff options
author | Ivan Chen <ivan@tagg.id> | 2021-03-12 17:10:28 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-12 17:10:28 -0500 |
commit | 34d94e1dff831aafa984a2f6c9b9b01e2e349154 (patch) | |
tree | 43555e2dc1edbb7b0719fbf61ed621868a79f0bb /src/utils/common.ts | |
parent | 3585aacbcfe148fa7ce1ed5d3d3fd33ac784be48 (diff) | |
parent | 2c9b2cf69d6e2fba44bcecb2636f51c94b8a64dd (diff) |
Merge pull request #294 from IvanIFChen/tma695-revamp-discover-screen
[TMA-695] Revamp Discover Screen
Diffstat (limited to 'src/utils/common.ts')
-rw-r--r-- | src/utils/common.ts | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/utils/common.ts b/src/utils/common.ts index 30122e79..c1049c42 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -94,3 +94,24 @@ export const haveUnreadNotifications = async ( } return false; }; + +// https://stackoverflow.com/a/2450976 +export const shuffle = (array: any[]) => { + var currentIndex = array.length, + temporaryValue, + randomIndex; + + // While there remain elements to shuffle... + while (currentIndex !== 0) { + // Pick a remaining element... + randomIndex = Math.floor(Math.random() * currentIndex); + currentIndex -= 1; + + // And swap it with the current element. + temporaryValue = array[currentIndex]; + array[currentIndex] = array[randomIndex]; + array[randomIndex] = temporaryValue; + } + + return array; +}; |