1
0
Code Issues Pull Requests Packages Projects Releases Wiki Activity GitHub Gitee

项目代码结构调整

This commit is contained in:
2024-12-07 18:10:44 +08:00
parent d7aa9ac403
commit 8354ebb1ca
13 changed files with 42 additions and 31 deletions

44
src/utils/utils.ts Normal file
View File

@@ -0,0 +1,44 @@
/**
* 比较两个字符串数组 `Array<string>` 是否相同
*
* @param array1 数组1
* @param array2 数组2
* @returns
* @since 2024-04-09
*/
export function isStringArrayEqual(array1: string[], array2: string[]) {
if (array1.length !== array2.length) {
return false;
}
for (let index = 0; index < array1.length; index++) {
const element1 = array1[index];
const element2 = array2[index];
if (element1 !== element2) {
return false;
}
}
return true;
}
/**
* 去除二维字符串数组中的重复数组元素
*
* 例如,输入 [["a", "b"], ["a", "b"], ["c", "d"]],会返回 [[ "a", "b"], ["c", "d"]],去除了重复出现的 ["a", "b"]。
*
* @param stringArr 要进行去重操作的二维字符串数组,即数组中每个元素又是一个字符串数组,代表一组相关的字符串元素集合。
* @returns 返回一个二维字符串数组其中已经去除了原输入二维数组中重复的元素组合基于JSON序列化后的字符串比较来判定重复与否。
* @since 2024-04-09
*/
export function stringListArrayDuplicateRemoval(stringArr: Array<string[]>): Array<string[]> {
const tempArr: Array<string> = [];
const newArr: Array<string[]> = [];
for (let index = 0; index < stringArr.length; index++) {
const element = stringArr[index];
const elementStr = JSON.stringify(element);
if (!tempArr.includes(elementStr)) {
newArr.push(element);
tempArr.push(elementStr);
}
}
return newArr;
}