mart-admin/src/utils/arrayOperation.ts

42 lines
1.1 KiB
TypeScript
Raw Normal View History

/**
*
* @param news
* @param old
* @returns `true`
*/
export function judementSameArr(news: unknown[] | string[], old: string[]): boolean {
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;
}
/**
*
* @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;
}