Skip to content

Instantly share code, notes, and snippets.

@joelturnbull
Created April 20, 2011 04:13
Show Gist options
  • Save joelturnbull/930327 to your computer and use it in GitHub Desktop.
Save joelturnbull/930327 to your computer and use it in GitHub Desktop.
double insert:into:
quantityOfIngredient: theIngredient
"return the accumulated quantity of an ingredient across all recipes"
^ recipes inject: 0 into: [ :totalQuantity :aRecipe |
aRecipe ingredients inject: totalQuantity into: [ :theTotalQuantity :anIngredient |
( theIngredient = anIngredient )
ifTrue: [ theTotalQuantity + anIngredient quantity ]
ifFalse: [ theTotalQuantity ]
]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment