mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-12-28 02:48:43 +08:00
refactor: move array related function to the arrays file
This commit is contained in:
parent
39e611d276
commit
5701f94b60
3 changed files with 18 additions and 12 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -99,3 +99,18 @@ export function nthElementFromArray<T>(
|
|||
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<T>(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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -555,15 +555,6 @@ export function isPasswordStrong(password: string): boolean {
|
|||
return hasCapital && hasNumber && hasSpecial && isLong && isShort;
|
||||
}
|
||||
|
||||
export function intersect<T>(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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue