CodingBat is an excellent resource for practicing method code; it played a significant role in my growth as a developer. Its author, Nick Parlante, offers simple algorithm challenges in an environment that provides immediate feedback with unit-tests.
Solving each of these puzzles in 5 to 20 line functions brings the same joys and benefits that practicing scales does for me as a musician.
We want to make a package of goal kilos of chocolate. We have small bars (1 kilo each) and big bars (5 kilos each). Return the number of small bars to use, assuming we always use big bars before small bars. Return -1 if it can’t be done.
repo can be
downloaded as a Zip file (or forked) on GitHub.
A text editor and web browser are all that are required to work through these problems. I feel that a simple browser-based QUnit setup offers a lower barrier to entry than other unit testing frameworks that require familiarity with the command line.
puzzle on Plunker:
Thanks to Brian Cleary for his input and ideas for this project.