go 笛卡尔乘积 实现sku

1数据源

[
    [
        {2714 白色 0xc000180d80 0xc0000f1110 0xc000044e40} 
        {2715 屎黄色 0xc000180ea0 0xc0000f11f0 0xc000044ea0}
        {2720 绿色 0xc000180fc0 0xc0000f1340 0xc000045020}
    ] 
    [
        {2717 纯棉 0xc000181320 0xc0000f1420 0xc000045380}
    ] 
    [
        {2716 30寸 0xc000181680 0xc0000f1500 0xc00099c2a0} 
        {2718 60寸 0xc0001817a0 0xc0000f15e0 0xc00099c300}
    ]
]

2代码实现

func(this *GoodsController)GetSku(goods_attrs [][]models.GoodsAttr)([][]models.GoodsAttr){
	arrlen:=len(goods_attrs)//列
	sku:=make([][]models.GoodsAttr,0)
	for _,val :=range goods_attrs[0] {
		temps := make([]models.GoodsAttr, 0)
		temps = append(temps,val)
		sku =append(sku,temps)
	}
	for i:=0;i<arrlen-1;i++{
		skuarr:=make([][]models.GoodsAttr,0)
		for _,val:=range sku{
			for _,vals :=range goods_attrs[i+1]{
				temp:=make([]models.GoodsAttr,0)
				temp=append(temp,val...)
				temp=append(temp,vals)
				skuarr=append(skuarr,temp)
			}
		}
		sku=skuarr
	}
	return sku
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值