November 18, 2014

Interview Cake Problem #8

I signed up for Interview Cake and got my first problem as promised.

I first tried to solve it using some function chaining with lodash‘s sort, filter, and reduce methods to toss out and sum up values. I wrote numerous tests against my max_duffel_bag_value() function with Mocha and used the command

mocha --watch cake-thief.js`

so I could watch my tests pass or fail on every save. I thought I had solved the problem, so I decided to look at the solution.

The sample input values in the solution failed when I added them to my mocha tests. The example solution was not what I expected, but was satisfying to follow and implement.

I used node.js as my programming environment instead of Python. Translating the solution provided by the site from Python to JS was not hard. Things worth noting:

I look forward to problem #2!