2021-06-19 17:49:42 +08:00
|
|
|
|
/**
|
|
|
|
|
* 判断两数组是否相同
|
|
|
|
|
* @param news 新数据
|
|
|
|
|
* @param old 源数据
|
|
|
|
|
* @returns 两数组相同返回 `true`,反之则反
|
|
|
|
|
*/
|
2022-02-21 23:52:59 +08:00
|
|
|
|
export function judementSameArr(news: unknown[] | string[], old: string[]): boolean {
|
2021-03-15 12:44:58 +08:00
|
|
|
|
let count = 0;
|
|
|
|
|
const leng = old.length;
|
|
|
|
|
for (let i in old) {
|
|
|
|
|
for (let j in news) {
|
|
|
|
|
if (old[i] === news[j]) count++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return count === leng ? true : false;
|
|
|
|
|
}
|
2021-08-01 18:30:30 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 判断两个对象是否相同
|
|
|
|
|
* @param a 要比较的对象一
|
|
|
|
|
* @param b 要比较的对象二
|
|
|
|
|
* @returns 相同返回 true,反之则反
|
|
|
|
|
*/
|
|
|
|
|
export function isObjectValueEqual(a: { [key: string]: any }, b: { [key: string]: any }) {
|
|
|
|
|
if (!a || !b) return false;
|
|
|
|
|
let aProps = Object.getOwnPropertyNames(a);
|
|
|
|
|
let bProps = Object.getOwnPropertyNames(b);
|
|
|
|
|
if (aProps.length != bProps.length) return false;
|
|
|
|
|
for (let i = 0; i < aProps.length; i++) {
|
|
|
|
|
let propName = aProps[i];
|
|
|
|
|
let propA = a[propName];
|
|
|
|
|
let propB = b[propName];
|
|
|
|
|
if (!b.hasOwnProperty(propName)) return false;
|
|
|
|
|
if (propA instanceof Object) {
|
|
|
|
|
if (!isObjectValueEqual(propA, propB)) return false;
|
|
|
|
|
} else if (propA !== propB) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|