Skip to content

Instantly share code, notes, and snippets.

@aaronshaf
Last active August 29, 2015 14:16
Show Gist options
  • Select an option

  • Save aaronshaf/560fc9168ca72d1059a1 to your computer and use it in GitHub Desktop.

Select an option

Save aaronshaf/560fc9168ca72d1059a1 to your computer and use it in GitHub Desktop.
// Confused? See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Array_comprehensions
function flatten(previous, current) {
return previous.concat(current)
}
var productImages = [
for(section of CatalogSections) [
for(placement of section.ProductPlacements) [
for(item of placement.ProductPlacementItems) [
for(image of item.Product.ProductImages) {
manufacturerName: item.Product && item.Product.Manufacturer ?
item.Product.Manufacturer.name : null,
distributorPartNumber: item.distributor_part_number,
manufacturerPartNumber: item.manufacturer_part_number,
imageName: image.name
}
].reduce(flatten, []).filter((product) => product.imageName)
].reduce(flatten, [])
].reduce(flatten, [])
].reduce(flatten, [])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment