Quick actions

cmd+k|ctrl+k

Navigation

Languages

Backend 01

Snippet info

Language

JavaScript

Visibility

public

Author

64160280

Created

2023-09-28T06:30:58.01497Z

Updated

2023-09-28T06:31:24.2897Z

/* ************************************
* 64160280
* Phachara Aunkitti : Authors
*************************************/
function exam01(alice, bob) {
    // Declare varibles
    let aliceCount = 0; //for count alice points
    let bobCount = 0; // for count bob points

    // loop for comparing value between alice and bob
    for (let round = 0; round < alice.length; round++) {
        if (alice[round] > bob[round]) { // condition to check if alice point more than bob point
            aliceCount++;
        }
        else if (alice[round] < bob[round]) { // condition to check if bob point more than point point
            bobCount++;
        }
    }
    // return aliceCount, bobCount are points of alice and bob.
    return [aliceCount, bobCount];
}

function test_01() {
    if (JSON.stringify(exam01([1, 2, 3], [7, 1, 3])) === JSON.stringify([1, 1])) {
        console.log("pass");
    } else {
        console.log("fail");
    }
}

test_01();
INFO