Created
October 5, 2011 19:12
-
-
Save davemo/1265355 to your computer and use it in GitHub Desktop.
last koans
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| it("should count the ingredient occurrence (functional)", function () { | |
| var ingredientCount = { "{ingredient name}": 0 }; | |
| _(products).chain() | |
| .map(function(product) { return product.ingredients; }) | |
| .flatten() | |
| .reduce(function(list, ingredient) { | |
| ingredientCount[ingredient] = (ingredientCount[ingredient] || 0) + 1; | |
| }); | |
| /* chain() together map(), flatten() and reduce() */ | |
| expect(ingredientCount['mushrooms']).toBe(2); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment