function deepClone(obj, hash = new WeakMap()) {
if (obj === null) return obj
if (obj instanceof Date) return new Date(obj)
if (obj instanceof RegExp) return new RegExp(obj)
if (typeof obj !== 'object') return obj
if (hash.get(obj)) return hash.get(obj)
let newObj = new obj.constructor()
hash.set(obj, newObj)
for (let key of Object.keys(obj)) {
newObj[key] = deepClone(obj[key], hash)
}
return newObj
}