-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNutritionInfo.js
40 lines (36 loc) · 1.1 KB
/
NutritionInfo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
class NutritionInfo{
constructor(calories = 0, protein = 0, sugars = 0, fat = 0){
this.calories = calories;
this.protein = protein;
this.sugars = sugars;
this.fat = fat;
}
add(other){
return new NutritionInfo(
this.calories + other.calories,
this.protein + other.protein,
this.sugars + other.sugars,
this.fat + other.fat
);
}
scale(factor){
return new NutritionInfo(
this.calories * factor,
this.protein * factor,
this.sugars * factor,
this.fat * factor
);
}
toCreator(indent){
var indentSpaces = "";
for(var i = 0; i < indent; i++){
indentSpaces += " ";
}
return indentSpaces + "new NutritionInfo(" +
indentSpaces + " " + this.calories + ",\n" +
indentSpaces + " " + this.protein + ",\n" +
indentSpaces + " " + this.sugars + ",\n" +
indentSpaces + " " + this.fats + "\n" +
indentSpaces + ")";
}
}