Skip to content

Instantly share code, notes, and snippets.

@davemo
Created October 5, 2011 19:12
Show Gist options
  • Select an option

  • Save davemo/1265355 to your computer and use it in GitHub Desktop.

Select an option

Save davemo/1265355 to your computer and use it in GitHub Desktop.
last koans
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