最长无重复字符串
var lengthOfLongestSubstring = function(s) {
let res=''
let index=0
let longStr=''
while(index<=s.length-1){
let curr=s[index]
if(!res.includes(curr)) res+=curr
else res=res.slice(res.indexOf(curr)+1)+curr
if(longStr.length<res.length) longStr=res
index++
}
return longStr.length
};
深拷贝
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
</head>
<body>
<script type="text/javascript">
const _completeDeepClone = (obj, map = new Map()) => {
if(obj===null||typeof obj!=='object'){
return obj;
}
if(map.has(obj)){
return map.get(obj);
}
if(obj instanceof Date){
return new Date(obj);
}
if(obj instanceof RegExp){
return new RegExp(obj);
}
if(typeof obj === 'function'){
return obj;
}
if(Array.isArray(obj)){
const copyArray=[]
map.set(obj,copyArray);
for(let i=0;i<obj.length;i++){
copyArray[i]=_completeDeepClone(obj[i],map)
}
return copyArray;
}
const copyObj={};
map.set(obj,copyObj);
for(const key in obj){
if(obj.hasOwnProperty(key)){
copyObj[key]=_completeDeepClone(obj[key],map)
}
}
return copyObj;
}
</script>
</body>
</html>