Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions frontend/src/ts/components/modals/CommandlineModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { intersect } from "@monkeytype/util/arrays";
import { areUnsortedArraysEqual, intersect } from "@monkeytype/util/arrays";
import {
For,
JSXElement,
Expand Down Expand Up @@ -42,7 +42,6 @@ import {
} from "../../states/test";
import { FaObject } from "../../types/font-awesome";
import { ValidationResult } from "../../types/validation";
import { areUnsortedArraysEqual } from "../../utils/arrays";
import { cn } from "../../utils/cn";
import { AnimatedModal } from "../common/AnimatedModal";
import { Fa } from "../common/Fa";
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ts/components/modals/EditResultTagsModal.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { areUnsortedArraysEqual } from "@monkeytype/util/arrays";
import { createEffect, createSignal, For } from "solid-js";

import { updateTags } from "../../collections/results";
Expand All @@ -10,7 +11,6 @@ import {
showSuccessNotification,
} from "../../states/notifications";
import { setResultTagsAfterEdit } from "../../states/result";
import { areUnsortedArraysEqual } from "../../utils/arrays";
import { createErrorMessage } from "../../utils/error";
import { AnimatedModal } from "../common/AnimatedModal";
import { Button } from "../common/Button";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import type {
} from "@monkeytype/schemas/configs";
import type { Mode } from "@monkeytype/schemas/shared";

import { areUnsortedArraysEqual } from "@monkeytype/util/arrays";
import { For, JSXElement, Show } from "solid-js";

import { setConfig, setQuoteLengthAll } from "../../config/setters";
import { getConfig } from "../../config/store";
import { isAuthenticated } from "../../states/core";
import { showModal } from "../../states/modals";
import { restartTest } from "../../test/test-logic";
import { areUnsortedArraysEqual } from "../../utils/arrays";
import { AnimatedModal } from "../common/AnimatedModal";
import { Button } from "../common/Button";
import { Separator } from "../common/Separator";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { CustomLayoutFluid } from "@monkeytype/schemas/configs";
import { areUnsortedArraysEqual } from "@monkeytype/util/arrays";
import { JSXElement } from "solid-js";

import { configMetadata } from "../../../../config/metadata";
import { setConfig } from "../../../../config/setters";
import { getConfig } from "../../../../config/store";
import { LayoutsList } from "../../../../constants/layouts";
import { areUnsortedArraysEqual } from "../../../../utils/arrays";
import SlimSelect from "../../../ui/SlimSelect";
import { SearchableSetting } from "../SearchableSetting";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CustomPolyglot as CustomPolyglotType } from "@monkeytype/schemas/configs";
import { areUnsortedArraysEqual } from "@monkeytype/util/arrays";
import { Optgroup } from "slim-select/store";
import { JSXElement } from "solid-js";

Expand All @@ -9,7 +10,6 @@ import {
LanguageGroupNames,
LanguageGroups,
} from "../../../../constants/languages";
import { areUnsortedArraysEqual } from "../../../../utils/arrays";
import { getLanguageDisplayString } from "../../../../utils/strings";
import SlimSelect from "../../../ui/SlimSelect";
import { SearchableSetting } from "../SearchableSetting";
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ts/components/pages/test/TestConfig.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { areUnsortedArraysEqual } from "@monkeytype/util/arrays";
import { ComponentProps, For, JSXElement, Show } from "solid-js";

import { configMetadata } from "../../../config/metadata";
Expand All @@ -14,7 +15,6 @@ import {
} from "../../../states/test";
import { restartTest } from "../../../test/test-logic";
import { FaObject } from "../../../types/font-awesome";
import { areUnsortedArraysEqual } from "../../../utils/arrays";
import { cn } from "../../../utils/cn";
import { Anime } from "../../common/anime";
import { Button } from "../../common/Button";
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/ts/components/ui/SlimSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import type { JSX, JSXElement } from "solid-js";

import { areUnsortedArraysEqual } from "@monkeytype/util/arrays";
import SlimSelectCore, { Config } from "slim-select";
import { Optgroup, Option } from "slim-select/store";
import { onMount, onCleanup, createEffect, createSignal } from "solid-js";

import { areUnsortedArraysEqual } from "../../utils/arrays";

// Helper: Update SlimSelect data and trigger renders
function updateSlimSelectData(
slimSelect: SlimSelectCore,
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ts/config/metadata.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { checkCompatibility } from "@monkeytype/funbox";
import * as ConfigSchemas from "@monkeytype/schemas/configs";
import { KnownFontName } from "@monkeytype/schemas/fonts";
import { areUnsortedArraysEqual } from "@monkeytype/util/arrays";
import { roundTo1 } from "@monkeytype/util/numbers";
import { typedKeys } from "@monkeytype/util/objects";
import { JSXElement } from "solid-js";
Expand All @@ -13,7 +14,6 @@ import { showNoticeNotification } from "../states/notifications";
import { setRandomTheme } from "../states/theme";
import { FaObject } from "../types/font-awesome";
import { Validation } from "../types/validation";
import { areUnsortedArraysEqual } from "../utils/arrays";
import { isDevEnvironment } from "../utils/env";
import { reloadAfter } from "../utils/misc";
import { capitalizeFirstLetter } from "../utils/strings";
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ts/controllers/challenge-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
getLoadedChallenge,
setLoadedChallenge,
} from "../states/test";
import { areUnsortedArraysEqual } from "../utils/arrays";
import { areUnsortedArraysEqual } from "@monkeytype/util/arrays";

let challengeLoading = false;

Expand Down
3 changes: 2 additions & 1 deletion frontend/src/ts/controllers/theme-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { getCustomTheme, getCustomThemes } from "../queries/custom-themes";
import { showNoticeNotification } from "../states/notifications";
import { debounce } from "throttle-debounce";
import { CustomThemeColors, ThemeName } from "@monkeytype/schemas/configs";
import { areSortedArraysEqual } from "@monkeytype/util/arrays";
import { Theme, themes, ThemesList } from "../constants/themes";
import { setThemeIndicator } from "../states/core";
import {
Expand Down Expand Up @@ -90,7 +91,7 @@ function updateThemeIndicator(nameOverride?: string): void {
if (Config.customTheme && nameOverride === undefined) {
// Match current custom theme by colors since Config does not store custom theme IDs
const matchedTheme = getCustomThemes().find((ct) =>
Arrays.areSortedArraysEqual(ct.colors, Config.customThemeColors),
areSortedArraysEqual(ct.colors, Config.customThemeColors),
);

if (matchedTheme) {
Expand Down
23 changes: 0 additions & 23 deletions frontend/src/ts/utils/arrays.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,29 +101,6 @@ export function lastElementFromArray<T>(array: T[]): T | undefined {
return array[array.length - 1];
}

/**
* Checks if two unsorted arrays are equal, i.e., they have the same elements regardless of order.
* @param a The first array.
* @param b The second array.
* @returns True if the arrays are equal, false otherwise.
*/
export function areUnsortedArraysEqual<T>(a: T[], b: T[]): boolean {
return a.length === b.length && a.every((v) => b.includes(v));
}

/**
* Checks if two sorted arrays are equal, i.e., they have the same elements in the same order.
* @param a The first array.
* @param b The second array.
* @returns True if the arrays are equal, false otherwise.
*/
export function areSortedArraysEqual<T>(
a: readonly T[],
b: readonly T[],
): boolean {
return a.length === b.length && a.every((v, i) => v === b[i]);
}

/**
* Returns a random element from an array.
* @param array The input array.
Expand Down
23 changes: 23 additions & 0 deletions packages/util/src/arrays.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,26 @@ export function intersect<T>(a: T[], b: T[], removeDuplicates = false): T[] {
});
return removeDuplicates ? [...new Set(filtered)] : filtered;
}

/**
* Checks if two unsorted arrays are equal, i.e., they have the same elements regardless of order.
* @param a The first array.
* @param b The second array.
* @returns True if the arrays are equal, false otherwise.
*/
export function areUnsortedArraysEqual<T>(a: T[], b: T[]): boolean {
return a.length === b.length && a.every((v) => b.includes(v));
}

/**
* Checks if two sorted arrays are equal, i.e., they have the same elements in the same order.
* @param a The first array.
* @param b The second array.
* @returns True if the arrays are equal, false otherwise.
*/
export function areSortedArraysEqual<T>(
a: readonly T[],
b: readonly T[],
): boolean {
return a.length === b.length && a.every((v, i) => v === b[i]);
}
Loading