function judgementSameArr(newArr, oldArr) {
  const news = removeDuplicate(newArr);
  const olds = removeDuplicate(oldArr);
  let count = 0;
  const leng = news.length;
  for (let i in olds) {
    for (let j in news) {
      if (olds[i] === news[j]) count++;
    }
  }
  return count === leng ? true : false;
}
function isObjectValueEqual(a, b) {
  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;
}
function removeDuplicate(arr, attr) {
  if (!arr.length) {
    return arr;
  } else {
    if (attr) {
      const obj = {};
      return arr.reduce((cur, item) => {
        const key = item[attr];
        if (key && !obj[key]) {
          obj[key] = true;
          cur.push(item);
        }
        return cur;
      }, []);
    } else {
      return [...new Set(arr)];
    }
  }
}
const clone = (value) => {
  if (!value) return value;
  if (Array.isArray(value)) return value.map((item) => clone(item));
  if (typeof value === "object") {
    return Object.fromEntries(
      Object.entries(value).map(([k, v]) => {
        return [k, clone(v)];
      })
    );
  }
  return value;
};

export { clone, isObjectValueEqual, judgementSameArr, removeDuplicate };
