function combine(...chunks) {
console.log(chunks)
let res = []
let helper = function (chunkIndex, prev) {
let chunk = chunks[chunkIndex].list
let name = chunks[chunkIndex].title
let isLast = chunkIndex === chunks.length - 1
for (let val of chunk) {
// console.log(val)
let cur = prev.concat( val )
if (isLast) {
// 如果已经处理到数组的最后一项了 则把拼接的结果放入返回值中
res.push({
specs: cur,
})
} else {
helper(chunkIndex + 1, cur)
}
}
}
// 从属性数组下标为 0 开始处理
// 并且此时的 prev 是个空数组
helper(0, [])
return res
}
const specList = [
{ title: "颜色", list: ["红色", "紫色", "白色", "黑色"] },
{ title: "套餐", list: ["套餐一", "套餐二", "套餐三", "套餐四"] },
{ title: "内存", list: ["64G", "128G", "256G"] }
]
let skuList=combine(...specList)
// console.log(skuList)
console