diff --git a/src/shared/components/apps.tsx b/src/shared/components/apps.tsx
index 2ad410e..f821a66 100644
--- a/src/shared/components/apps.tsx
+++ b/src/shared/components/apps.tsx
@@ -13,6 +13,7 @@ import {
} from "./app-definitions";
import { Icon } from "./icon";
import { I18nKeys } from "i18next";
+import { sortRandom } from "../utils";
const TitleBlock = () => (
@@ -146,6 +147,9 @@ export class Apps extends Component
{
apps = apps.filter(a => a.platforms.includes(this.state.platform));
}
+ // Random sort
+ apps = sortRandom(apps);
+
this.setState({ apps });
}
diff --git a/src/shared/components/instances.tsx b/src/shared/components/instances.tsx
index 19259c8..e086018 100644
--- a/src/shared/components/instances.tsx
+++ b/src/shared/components/instances.tsx
@@ -3,7 +3,7 @@ import { Helmet } from "inferno-helmet";
import { i18n, LANGUAGES } from "../i18next";
import { T } from "inferno-i18next";
import { instance_stats } from "../instance_stats";
-import { getQueryParams, mdToHtml, numToSI } from "../utils";
+import { getQueryParams, mdToHtml, numToSI, sortRandom } from "../utils";
import { Badge, SELECT_CLASSES, SectionTitle, TEXT_GRADIENT } from "./common";
import {
INSTANCE_HELPERS,
@@ -351,13 +351,6 @@ const LEAST_ACTIVE_SORT: Sort = {
const SORTS: Sort[] = [RANDOM_SORT, MOST_ACTIVE_SORT, LEAST_ACTIVE_SORT];
-function sortRandom(instances: any[]): any[] {
- return instances
- .map(value => ({ value, sort: Math.random() }))
- .sort((a, b) => a.sort - b.sort)
- .map(({ value }) => value);
-}
-
function sortActive(instances: any[]): any[] {
return instances.sort(
(a, b) =>
diff --git a/src/shared/utils.ts b/src/shared/utils.ts
index 1866f06..031b3d1 100644
--- a/src/shared/utils.ts
+++ b/src/shared/utils.ts
@@ -57,3 +57,10 @@ export function monthsBetween(startDate: Date, endDate: Date) {
// Convert back to days and return
return Math.round(differenceMs / oneMonth);
}
+
+export function sortRandom(list: T[]): T[] {
+ return list
+ .map(value => ({ value, sort: Math.random() }))
+ .sort((a, b) => a.sort - b.sort)
+ .map(({ value }) => value);
+}