lundi 24 décembre 2018

passing a function in the if statement condition filed

My question is about best practice, I have a long if else statement, I am wondering if I can extract the conditions to a separate function and then pass them as the condition. Please see below =>

if (functionA (a, b)) {
    // do something
} else if (functionB (a, b)) {
    // do something else 
}

functionA (a, b) {
    return a - b === 0
}

functionB (a, b) {
    return a * b != 1
}

Aucun commentaire:

Enregistrer un commentaire