Skip to content

Instantly share code, notes, and snippets.

@gingerrific
Last active August 29, 2015 14:01
Show Gist options
  • Save gingerrific/e3b8649c4c2011c31834 to your computer and use it in GitHub Desktop.
Save gingerrific/e3b8649c4c2011c31834 to your computer and use it in GitHub Desktop.
var averagePrice = items.reduce(function (arrayZero, arrayOne) {
return {price: arrayZero.price + arrayOne.price};
})
averagePrice.price = +(averagePrice.price/items.length).toFixed(2);
// averagePrice.price = +(averagePrice.price).toFixed(2);
console.log("The average price is $", averagePrice.price);
items.forEach(function (array) {
if (array.currency_code == "GBP") {
console.log(array.title + " Costs £" + array.price)
}
})
var materials = items.map(function(item) {
return item.materials.forEach (function (mat) {
if (mat == "wood") {
console.log(item.title, "is made of wood")
}
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment