Sample test indicates that return value should be a string but actual tests expect number.
Comparing floating point values rounded is rather inferior to comparing them approximately, but letting that slide; it's too late to change that now.
Well, that was half fixed. Leaving it at that.
sometimes there is www1 , www2 ... but other than that , the code is good and elegant
You can... but I can't really think of how it would help you. .reverse() hasn't been locked. You can't reverse a 2D array with .reverse(), though.
Please use Test.assertEquals instead of Test.expect for the tests for better test feedback.
I just removed equilibrium part and added consumer surplus.
They have to find equilibrium points to answer this question anyway.
Also I made constant of supply curve negative, does it solve the negative prices problem?
Or not have one call the other, have it do its own calculation without intermediate rounding. Is that an option?
Yeah, but I was wondering what should I do with these random equilibrium function that end up with endless decimal digits.
So maybe I should change the kata to find only the producer surplus?
I haven't actually done all the expansion, but in the producer surplus calculation, we are told to use the equilibrium function, and then we still need to calculate the zero supply price. That means parsing the supply curve anyway, so depending on the equilibrium function doesn't really save any work. I could have just copied the curve parsing code .. wait, I did.
Producer surplus function does not need to depend on equilibrium function, it could just be doing its own calculations.
In the example, producers are willing to supply at negative prices. Not the most ideal example.
Rounding intermediate results. Bad practice.
But producers are willing to supply at negative prices, which makes it not a very good example.
The linked Wikipedia page has the calculation (which also takes the zero supply price as an argument).
This comment is hidden because it contains spoiler information about the solution