export function compare<T>(val1: T, val2: T): boolean {
  if (!val1 && !val2) {
    return true;
  }

  if (!!val1 && !val2) {
    return false;
  }

  if (typeof val1 !== typeof val2) {
    return false;
  }

  if (Array.isArray(val1) && Array.isArray(val2)) {
    if (val1.length !== val2.length) {
      return false;
    }

    for (let index = 0; index < val1.length; index++) {
      if (!compare(val1[index], val2[index])) {
        return false;
      }
    }

    return true;
  }

  if (typeof val1 === 'object') {
    if (Object.keys(val1).length !== Object.keys(val2).length) {
      return false;
    }

    for (const key in { ...val1, ...val2 }) {
      if (val1.hasOwnProperty(key) && val2.hasOwnProperty(key)) {
        if (!compare(val1[key], val2[key])) {
          return false;
        }
      } else {
        return false;
      }
    }
    return true;
  }

  return val1 === val2;
}
