Recipe.js 709 B

1234567891011121314151617181920212223
  1. class Recipe{
  2. constructor(id, name, price, ingredients, parent){
  3. this.id = id;
  4. this.name = name;
  5. this.price = price;
  6. this.parent = parent;
  7. this.ingredients = [];
  8. for(let i = 0; i < ingredients.length; i++){
  9. for(let j = 0; j < parent.ingredients.length; j++){
  10. if(ingredients[i].ingredient === parent.ingredients[j].ingredient.id){
  11. this.ingredients.push({
  12. ingredient: parent.ingredients[j].ingredient,
  13. quantity: ingredients[i].quantity
  14. });
  15. break;
  16. }
  17. }
  18. }
  19. }
  20. }
  21. module.exports = Recipe;