diff --git a/frontend/src/ts/test/funbox/funbox-validation.ts b/frontend/src/ts/test/funbox/funbox-validation.ts index 9325daaea119..7a4deb00811d 100644 --- a/frontend/src/ts/test/funbox/funbox-validation.ts +++ b/frontend/src/ts/test/funbox/funbox-validation.ts @@ -1,6 +1,6 @@ import * as FunboxList from "./funbox-list"; import * as Notifications from "../../elements/notifications"; -import * as Misc from "../../utils/misc"; +import * as Arrays from "../../utils/arrays"; import * as Strings from "../../utils/strings"; export function checkFunboxForcedConfigs( @@ -44,7 +44,7 @@ export function checkFunboxForcedConfigs( key ] as SharedTypes.ConfigValue[]; } else { - forcedConfigs[key] = Misc.intersect( + forcedConfigs[key] = Arrays.intersect( forcedConfigs[key] as SharedTypes.ConfigValue[], fb.forcedConfig[key] as SharedTypes.ConfigValue[], true @@ -305,7 +305,7 @@ export function areFunboxesCompatible( for (const key in f.forcedConfig) { if (allowedConfig[key]) { if ( - Misc.intersect( + Arrays.intersect( allowedConfig[key] as SharedTypes.ConfigValue[], f.forcedConfig[key] as SharedTypes.ConfigValue[], true diff --git a/frontend/src/ts/utils/arrays.ts b/frontend/src/ts/utils/arrays.ts index 772e56223514..1dec3ce0ddb0 100644 --- a/frontend/src/ts/utils/arrays.ts +++ b/frontend/src/ts/utils/arrays.ts @@ -99,3 +99,18 @@ export function nthElementFromArray( index = index < 0 ? array.length + index : index; return array[index]; } + +/** + * Returns the intersection of two arrays, i.e., the elements that are present in both arrays. + * @param a First array. + * @param b Second array. + * @returns An array containing the elements that are present in both input arrays. + */ +export function intersect(a: T[], b: T[], removeDuplicates = false): T[] { + let t; + if (b.length > a.length) (t = b), (b = a), (a = t); // indexOf to loop over shorter + const filtered = a.filter(function (e) { + return b.includes(e); + }); + return removeDuplicates ? [...new Set(filtered)] : filtered; +} diff --git a/frontend/src/ts/utils/misc.ts b/frontend/src/ts/utils/misc.ts index dcd294dcf9a2..647e1aff8461 100644 --- a/frontend/src/ts/utils/misc.ts +++ b/frontend/src/ts/utils/misc.ts @@ -555,15 +555,6 @@ export function isPasswordStrong(password: string): boolean { return hasCapital && hasNumber && hasSpecial && isLong && isShort; } -export function intersect(a: T[], b: T[], removeDuplicates = false): T[] { - let t; - if (b.length > a.length) (t = b), (b = a), (a = t); // indexOf to loop over shorter - const filtered = a.filter(function (e) { - return b.includes(e); - }); - return removeDuplicates ? [...new Set(filtered)] : filtered; -} - export function htmlToText(html: string): string { const el = document.createElement("div"); el.innerHTML = html;