Skip to content

Instantly share code, notes, and snippets.

@Caballerog
Created June 11, 2024 11:05
Show Gist options
  • Save Caballerog/ea89d49a839248a8c033282f77efabd6 to your computer and use it in GitHub Desktop.
Save Caballerog/ea89d49a839248a8c033282f77efabd6 to your computer and use it in GitHub Desktop.
import { Ingredient } from './ingredient';
export class Recipe {
name: string;
ingredients: Ingredient[] = [];
recipes: Recipe[] = [];
constructor(name: string) {
this.name = name;
}
addIngredient(ingredient: Ingredient): void {
this.ingredients.push(ingredient);
}
addRecipe(recipe: Recipe): void {
this.recipes.push(recipe);
}
showDetails(): string {
let details = `Recipe: ${this.name}\n`;
this.ingredients.forEach(ingredient => {
details += ` ${ingredient.showDetails()}\n`;
});
this.recipes.forEach(recipe => {
details += ` ${recipe.showDetails()}`;
});
return details;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment