判断typeof olddata[key] === 'object'要注意要先判断olddata[key]不是null才行!否则程序会报错!!!
if (olddata[key]&&typeof olddata[key] === 'object') {
obj[key] = olddata[key].constructor === Array ? [] : {}
this.deepCopy(olddata[key], obj[key])
} else {
obj[key] = olddata[key]
}
if (olddata[key]&&typeof olddata[key] === 'object') {
obj[key] = olddata[key].constructor === Array ? [] : {}
this.deepCopy(olddata[key], obj[key])
} else {
obj[key] = olddata[key]
}
2022-07-18
var twoSum = function(nums, target) {
const map = new Map()
for (let i = 0; i < nums.length; i++) {
const num = nums[i]
let o =target -num
if (map.has(o)) return [i,map.get(o)]
map.set(num, i)
}
};
const map = new Map()
for (let i = 0; i < nums.length; i++) {
const num = nums[i]
let o =target -num
if (map.has(o)) return [i,map.get(o)]
map.set(num, i)
}
};
2022-04-29
function deepClone(params) {
const initData = params instanceof Array ?[]:{}
for (const i in params) {
initData[i]= params[i] instanceof Object ? deepClone(params[i]):params[i]
}
return initData
}
const initData = params instanceof Array ?[]:{}
for (const i in params) {
initData[i]= params[i] instanceof Object ? deepClone(params[i]):params[i]
}
return initData
}
2022-04-29