var products = [
Product(name: "Kayak", description: "A boat for one person",price: 275, stock: 10),
Product(name: "Lifejacket", description: "Protective and fashionable",price: 48.95, stock: 14),
return product.price * 0.2;
return productsArray.reduce(0, {(total, product) -> Double in
return total + (product.price * Double(product.stock))
});
}
Product(name: "Kayak", description: "A boat for one person",price: 275, stock: 10),
Product(name: "Lifejacket", description: "Protective and fashionable",price: 48.95, stock: 14),
Product(name: "Soccer Ball", description: "FIFA-approved size and weight",price: 19.5, stock: 32)];
return product.price * 0.2;
}
//这个函数是什么意思?
return productsArray.reduce(0, {(total, product) -> Double in
return total + (product.price * Double(product.stock))
});
}