Eric Carraway developer

CodingBat Problems in JavaScript

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.

CodingBat features problems in Java and Python.  I’m working towards solving the problems with JavaScript.  The in-progress project is on GitHub.

Sample Problem

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.

CodingBat JavaScript

Setup

The

1
codingbat-js
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.

Future Plans

Ideally, a user would be able to go to a website and complete challenges in a purely browser-based environment.  A few options exist for building a client-side JavaScript sandbox.  A simpler solution, however, is to use a service like JSFiddle, CodePen, or Plunker.

Here’s the

1
makeChocolate
puzzle on Plunker:

http://plnkr.co/edit/JnkDlo?p=preview

Thanks

Thanks to Brian Cleary for his input and ideas for this project.

CodingBat and its materials are copyright Nick Parlante.