aboutsummaryrefslogtreecommitdiff
path: root/src/utils/common.ts
diff options
context:
space:
mode:
authorIvan Chen <ivan@tagg.id>2021-03-11 18:22:24 -0500
committerIvan Chen <ivan@tagg.id>2021-03-11 18:22:24 -0500
commitb568f553c4ee2f0452f6bb7ab7b03c84d77c15ab (patch)
treeb8aab3b6720b111e57a8e543eb024ea7e7bdcc22 /src/utils/common.ts
parente63394198f554c7a302c12d8c540c1d730f65d86 (diff)
new discover users screen
Diffstat (limited to 'src/utils/common.ts')
-rw-r--r--src/utils/common.ts21
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;
+};