EasyTypeScript

Builder

TypeScriptDesign PatternsCreationalBuilder

Construct a complex object step by step through a fluent, chainable API instead of one giant constructor call.

Implement `PizzaBuilder`: setSize(size) and addTopping(topping) each return this so calls chain, and build() returns the final { size, toppings }.

solve(steps) replays a list of { op: 'setSize' | 'addTopping', value } steps against a fresh builder and returns the built pizza.

Sample tests

Test #1Chained size + two toppings
Input: [[{"op":"setSize","value":"large"},{"op":"addTopping","value":"cheese"},{"op":"addTopping","value":"olives"}]]
Output: {"size":"large","toppings":["cheese","olives"]}
Test #2Defaults with no steps
Input: [[]]
Output: {"size":"medium","toppings":[]}
Test #3Default size, one topping
Input: [[{"op":"addTopping","value":"mushroom"}]]
Output: {"size":"medium","toppings":["mushroom"]}