// function jiecheng (n) {
// sum = 1
// for (let i = 1; i <= n; i++) {
// sum = sum * i
// }
// return sum
// }
function jiecheng(n) {
if (n === 1) return 1
return n * jiecheng(n - 1)
}
console.log(jiecheng(3))
function feibo(n) {
if (n === 1 || n === 2) return 1
return feibo(n - 1) + feibo(n - 2)
}
console.log(feibo(10))
data = [
{
id: '1',
name: 'scn',
goods: [
{
id: '11',
name: 'csc',
goods:[
{
id:'125',
name: '12'
}
]
},
{
id: '12',
name: 'csc'
}
]
},
{
id: '2',
name: 'csdvdc'
}
]
function da(id, data) {
id = id.toString()
obj = {}
data.forEach((item, index) => {
if (item.id === id) {
obj = data[index]
} else if (item.goods && item.goods.length > 0) {
da(id, item.goods)
} else {
return null
}
})
return obj
}
console.log(da(125, data))
let obj1 ={
id:1,
d:2,
msk: {
jk:1,
sc:2
}
}
let obj2 = {...obj1}
obj1.id = 5
console.log(obj1, obj2)
console