Videos XXX
Remonter en Haut

Isomorphic Go by Kamesh Balasubramanian


Isomorphic Go by Kamesh Balasubramanian

Author:Kamesh Balasubramanian
Language: eng
Format: epub
Tags: COM060160 - COMPUTERS / Web / Web Programming, COM061000 - COMPUTERS / Client-Server Computing, COM051260 - COMPUTERS / Programming Languages / JavaScript
Publisher: Packt Publishing
Published: 2017-12-28T06:54:43+00:00


products := r.GetProducts()

productsMap := r.GenerateProductsMap(products)

result := make(models.Products, 0)

for _, v := range cart.Items {

product := &models.Product{}

product = productsMap[v.ProductSKU]

product.Quantity = v.Quantity

result = append(result, product)

}

sort.Sort(result)

return result

}

The job of this method is to return a slice of Product objects for all the products that exist within a shopping cart. The ShoppingCart struct simply keeps track of a product's type (through its SKU code) and the Quantity of that product in the shopping cart.

We declare a result variable, which is a slice of the Product objects. We loop through each shopping cart item, and we retrieve the Product object from the productsMap, providing the product's SKU code as the key. We populate the Quantity field of the Product object and append the Product object to the result slice.

We call the Sort method from the sort package passing in the result slice. Since we have implemented the sort interface for the Products type, the Product objects in the result slice will be sorted by price in the ascending order. Finally, we return the result slice.



Loading...
Download




Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.