I would like to raise an issue related to yesterday's JS OOP workshops. I think that for me, as maybe for most of you, the hardest part of task was actually the last method of getShoppingCart() function - getInfo(). We had to agregate all products from the cart to one array of objects, where single element represents all occurances (if more than one) of certain product.
After couple of hours, I came to conclusion that there were more than one ways to solve this problem.
(1) One of them, more time-absorbing, was to make getInfo() method create array (products = ) every time when invoked.
(2) Second, in my opinion much simpler, was to make getShoppingCart() function store and update array of objects dynamically - every time, when product is added. Then getInfo() method has only to return this array. And this is the way that I firstly chose.
(link to picture: http://pl.tinypic.com/r/2emewcw/9 )
As you can see, array of objects for further usage by getInfo() method is being constructed dynamically after every single invocation of add() method (it works a little bit differently with remove() method, but works).
Meanwhile, mocha test for this task forbids us to go this way. Why? Take a look here:
(link to picture: http://pl.tinypic.com/r/n6atk2/9 )
in final test (the one checking getInfo() method) we can see, that there is actually push() method being used instead of add(), when products are being added to cart. In my case - that prevents function buildProductInfo() from being invoked when it's needed. In the same time, we've been asked explicity to construct method add() for adding new products to cart.
I would like to mention, that I've fixed this problem already by changing my solution, so now it sticks to requirements provided by mocha tests.
BUT I was able to do so only because we're allowed to read the actual test file in this course. If it was exam - I propably wouldn't figure out where is the problem, despite the fact that my code is working as expected accordingly to requirements posted in GitHub - in 100%!
So here we come to my actual set of questions:
1. will we be informed explicity during exam, how our code is demanded to being designed? I mean - if it'd come to problem as described above - BGcoder won't give me points even though I've solved task correctly. What next then?
2. how did you people handle this problem? Show your code, this task was interesting one, so I think it'd be good to discuss it! :)