function deepClone(obj,cache = new Map()){
if(cache.get(obj)){
return cache.get(obj)
}
if(obj instanceof Object){
let dist ;
if(obj instanceof Array){
dist = [];
}else if(obj instanceof Function){
dist = function () {
return obj.call(this, ...arguments);
};
}else if(obj instanceof RegExp){
dist = new RegExp(obj.source,obj.flags);
}else if(obj instanceof Date){
dist = new Date(obj);
}else{
dist = {};
}
cache.set(obj, dist);
for(let key in obj){
if (obj.hasOwnProperty(key)) {
dist[key] = deepClone(obj[key], cache);
}
}
return dist;
}else{
return obj;
}
}