I used loop for comparing every each one of the values from 2 different Objects'. Because when I want to change the variables, this way is more simple and readable rather than just using massive if if if ... to compare all of the values 1 by 1 every single time.
This is the code:
// Get values from the default and options
var defaultValues = Object.values(this.getDefaults),
newValues = Object.values(this.options);
// Used loop for counting every single values from the Objects'
var checkDef = defaultValues.reduce((acc, cur) => acc + cur),
checkNew = newValues.reduce((acc, cur) => acc + cur);
// Compare between those 2 different variables.
if (checkDef === checkNew) {
console.log('true');
setInterval(() => {
this.runAnimate(this.initial[1], 1)
}, this.getDefaults.countdown);
} else {
console.log('false');
setInterval(() => {
this.runAnimate(this.initial[1], 1)
}, this.options.countdown);
}
but how would I write the code when if I want to run a different function based on the different conditions?
At first I tried to make new if statement but it would've caused unnecessary checking(literally, double checking) since I've compared whole the values by using loop the above. Thus, giving another if is just totally wasting imo.
// Give another if to compare a specific condition
if (this.getDefaults.skew === this.options.skew) {
// ... execute function1
else {
// ... execute function2
}
Is this unavoidable to give another if statement for comparing specific values in my case?
Aucun commentaire:
Enregistrer un commentaire