Как сократить такой код, пробовал создать функцию и передавать параметр при вызове, но в в Angular не сработало.
Спасибо
$scope.formula = function () {
var formula = 0, wight = $scope.wight.wight, height = $scope.height.height, age = $scope.age.age;
if($scope.Gender == 1.2){
formula = 66 + (13.7 * wight) + (5 * height) - (6.8 * age);
}
else{
formula = 655 + (9.6 * wight) + (1.8 * height) - (4.7 * age);
}
return formula.toFixed(0);
};
$scope.formula();
$scope.difference = function(){
var difference = $scope.total() - $scope.formula();
return difference.toFixed(0);
}
$scope.difference();
$scope.bicycle = function(){
var bicycle = $scope.difference() / 6.5;
if(bicycle < 0){
return 0;
}
else{
return bicycle.toFixed(0);
}
}
$scope.bicycle();
$scope.DistanceBike = function(){
var DistanceBike = $scope.bicycle() / 60 * 20;
return DistanceBike.toFixed(0);
}
$scope.DistanceBike();
$scope.run = function(){
var run = $scope.difference() / 9;
if(run < 0){
return 0;
}
else{
return run.toFixed(0);
}
}
$scope.run();
$scope.DistanceRun = function(){
var DistanceRun = $scope.run() / 60 * 10;
return DistanceRun.toFixed(0);
}
$scope.DistanceRun();
$scope.walk = function(){
var walk = $scope.difference() / 4;
if(walk < 0){
return 0;
}
else{
return walk.toFixed(0);
}
}
$scope.walk();
$scope.DistanceWalk = function(){
var DistanceWalk = $scope.walk() / 60 * 5;
return DistanceWalk.toFixed(0);
}
$scope.DistanceWalk();
$scope.exercises = function(){
var exercises = $scope.difference() / 3;
if(exercises < 0){
return 0;
}
else{
return exercises.toFixed(0);
}
}
$scope.exercises();
$scope.DistanceExercises = function(){
var DistanceExercises = $scope.exercises() / 60 * 20;
return DistanceExercises.toFixed(0);
}
$scope.DistanceExercises();
$scope.swim = function(){
var swim = $scope.difference() / 7;
if(swim < 0){
return 0;
}
else{
return swim.toFixed(0);
}
}
$scope.swim();
$scope.DistanceSwim = function(){
var DistanceSwim = $scope.swim() / 60 * 5;
return DistanceSwim.toFixed(0);
}
$scope.DistanceSwim();