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;
}
@Qiki
Copy link
Author

Qiki commented Apr 6, 2016

@GingerBear
Copy link

如果只有一个,还是large image,我们就不管了

我觉得应该,是如果只有一个,还是large image,我们就array add product,然后不管了

如果只有一个,还是小image,我们就把当前的product 加进去。

如果只有一个,还是小image,我们就把当前的product 加进去,然后不要row add innerArray

@Qiki
Copy link
Author

Qiki commented Apr 6, 2016

rows = [];
smallImageArray = [];
for (product in products) {
    largeImageProducts = [];

    if (product image is large) {
        [largeImageProducts addObject:product];
       [rows addObject:largeImageProducts];
    } else {
        if (smallImageProducts.count < 2) {
            [smallImageProducts addObject:product];
        } else {
            smallImageProducts = [];
            [smallImageProducts addObject:product];
        }

       [rows addObject:lsmallImageArray];
    }
}

@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) {
          if (product._bb_group) {
            rows.append(product._bb_group);
          }
          line.append(product);
        } else {
          rows.last().append(product);
          continue;
        }
      } eles {
        if (product._bb_group) {
          rows.append(product._bb_group);
        }
        line.append(product);
      }
    } else {
      if (product._bb_group) {
        rows.append(product._bb_group);
      }
      line.append(product);
    }
  }

 rows.append(line);
}

@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