Method Deck / cooking

Recipe scaling

Scales a list of ingredient quantities from an original serving count to a desired serving count.

Published for review. The Founder is checking every card himself; anything he strikes comes down the same hour.

Try it

Inputs

Outputs

Steps

  1. scale_factor = desired_servings / original_servings.
  2. For each ingredient, scaled_quantity = quantity * scale_factor, rounded to 2 decimals.
  3. Unit and name pass through unchanged; only quantity is scaled.

Constants

None.

Sources

Worked example and test vectors

NameInputsAnswer
worked example{"original_servings":4,"desired_servings":6,"ingredients":[{"name":"flour","quantity":200,"unit":"g"},{"name":"sugar","quantity":100,"unit":"g"},{"name":"eggs","quantity":2,"unit":"count"}]}300 g flour, 150 g sugar, 3 count eggs
test vector: fractional scale down{"original_servings":12,"desired_servings":5,"ingredients":[{"name":"butter","quantity":240,"unit":"g"},{"name":"chocolate chips","quantity":360,"unit":"g"}]}100 g butter, 150 g chocolate chips

Published card