I have this kind of multi-nested if-else block. My understanding is that there is a 'data-driven' approach that can help eliminate the need for it and trim down the code, however, I'm not experienced with it in a large way yet, so can anyone help me refactor this code to work in the 'data-driven' approach?
function (arg1) {
if(this.thing[arg1]){
// there is a valid property for this arg1
if(this.thing.a){
// there exists an 'a' propertie also
if(this.thing.a.arg1 == arg1){
// the a property has a property is the same as the arg1
// if this 'a' has a number higher than 0, avoid doing anything
if(this.thing.a.number > 0){
}else{
// 'a' number was 0 or lower, so we do something
this.thing.a = this.thing[arg1];
this.thing.a.arg1 = arg1;
}
}else{
// the' a' is not the arg1
// so we want to use the current arg1!
// but only if its 'number' is lower than 1
if(this.thing.a.number > 0){
}else{
// 'a' number was 0 or lower, so we do something
this.thing.a = this.thing[arg1];
this.thing.a.arg1 = arg1;
}
}
}else{
// there is no thing.a so we set it to arg1
this.thing.a = this.thing[arg1];
this.thing.a.arg1 = arg1;
}
}
}