Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ParthBarot-BoTreeConsulting/04f4813c70245c3ed03558026eae4a08 to your computer and use it in GitHub Desktop.
Save ParthBarot-BoTreeConsulting/04f4813c70245c3ed03558026eae4a08 to your computer and use it in GitHub Desktop.
JS refactoring - Fist version
var MyApp = {};
MyApp.Base = {
getFixedVal: function(){
//Javascript code before refactoring
var myDataVal = someCalculationHere();
var amount = someInputFieldValue;
var fixedVal = 0;
if(myDataVal > 12){
if(0 < amount && amount <= 12000){
if(calculatedVal <= 95){
fixedVal = 0.8;
}else{
fixedVal = 0.7;
}
}else{
if(calculatedVal <= 95){
fixedVal = 1.0;
}else{
fixedVal = 1.1;
}
}
} else if(0 < myDataVal && myDataVal < 12) {
if(0 < amount && amount <= 12000){
if(calculatedVal <= 90){
fixedVal = 0.4;
}else{
fixedVal = 0.7;
}
}else{
if(calculatedVal <= 78){
fixedVal = 0.4;
}else if(calculatedVal >= 78.01 && calculatedVal <= 90){
fixedVal = 0.7;
}else if(calculatedVal > 90){
fixedVal = 0.9;
}
}
}
return fixedVal;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment