dimanche 23 avril 2017

How can I shortcut this javascript if() entry?

what I wanted to do, was to check if all elements of array are different from undefined. Array_main contains 9 elements. I've created an if which, looks like that one below:

Question is: Is it possible to shortcut this if entry somehow?

// Function checking is there a tie - 0:0
var check_if_tie = function () {
if( array_main[0] !== undefined && array_main[1] !== undefined && 
    array_main[2] !== undefined && array_main[3] !== undefined && 
    array_main[4] !== undefined && array_main[5] !== undefined && 
    array_main[6] !== undefined && array_main[7] !== undefined && 
    array_main[8] !== undefined ) {
    alert("TIE!/REMIS!");
    return false;
} else {
    console.log('Continue playing');
    return false;
}   

};

Aucun commentaire:

Enregistrer un commentaire