Skip to content

Instantly share code, notes, and snippets.

@Qiki
Created April 6, 2016 17:25
Show Gist options
  • Save Qiki/3c9f20d887505faa307ddb176fd8a337 to your computer and use it in GitHub Desktop.
Save Qiki/3c9f20d887505faa307ddb176fd8a337 to your computer and use it in GitHub Desktop.
row = [];// outer array
for (product in productsArray) {
innerArray = []; // inner array
if (product.image is large) {
array add product;
} else if (product image is small) {
把row 数组的最后一个拿出来,看看
如果只有一个,还是large image,我们就不管了
如果只有一个,还是小image,我们就把当前的product 加进去。
}
}
row add innerArray;
}
@GingerBear
Copy link

rows = [];// outer array

for (product in productsArray) {
  line = []; // inner array

  if (product.image is large)  {
    line.append(product);
  }

  else if (product.image is small) {

    if (rows.last().length === 1) {
      if (rows.last()[0].image is small) {

        if (product._bb_group) {
          line.append(product);
        } else {
          rows.last().append(product);
          continue;
        }
      } eles {
        line.append(product);
      }
    } else {
      line.append(product);
    }
  }

 rows.append(line);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment