Today I tackled the Exact Change Challenge from Free Code Camp. Some work friends and I discussed this problem over lunch a few days ago and I was eager to get my hands on it.
This solution is my preliminary version. It technically makes all the tests go green, but it is very bulky and has a lot of nesting. My goal is to refactor this in a more declarative, functional style.
I learned some interesting stuff in the process, for example, the native Number.prototype.toFixed() method in JavaScipt is used to convert a number to a decimal using fixed-point notation. Example use:
However it returns a string instead of an actual number. So then parseFloat has to be called on the result.