1-100
function fnsum (n1,n2) {
var sum = n1 + n2
if (n2 + 1 > 100) {
return sum
} else {
return fnsum(sum, n2+1)
}
}
console.log(fnsum(1,2))
兔子
function tuzi(m1){
if(m1 <= 2) {
return 1
} else {
return tuzi(m1-1) + tuzi(m1-2)
}
}
console.log(tuzi(6))
深拷贝
function deepcopy(source) {
var targetObj = source.constructor === Array ? []:{}
for(let key in source) {
if (source[k] && typeof source[k] === "object"){
targetObj[k] = source[k].constructor ===Array?[]:{}
targetObj[k] = deepcopy(source[k])
} else {
targetObj[k] = source[k]
}
}
return targetObj
}