swift 一疑问:reduce

前端之家收集整理的这篇文章主要介绍了swift 一疑问:reduce前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
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),

Product(name: "Soccer Ball",description: "FIFA-approved size and weight",price: 19.5,stock: 32)];


func calculateTax(product:Product) -> Double {
return product.price * 0.2;

}

//这个函数是什么意思?

func calculateStockValue(productsArray:[Product]) -> Double {
return productsArray. reduce(0,{(total,product) -> Double in return total + (product.price * Double(product.stock)) }); } 原文链接:https://www.f2er.com/swift/326364.html

猜你在找的Swift相关文章