Skip to content

Instantly share code, notes, and snippets.

@bflannery
Created January 15, 2017 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bflannery/a7894468d26cd34fe6b370a9fefa9916 to your computer and use it in GitHub Desktop.
Save bflannery/a7894468d26cd34fe6b370a9fefa9916 to your computer and use it in GitHub Desktop.
Compare the values of 2 arrays
//Compare the values of 2 arrays.
//If Alice[i] > Bob[i], then Alice is awarded 1 point.
//If Alice[i] < Bob[i] , then Bob is awarded 1 point.
//If Alice[i] = Bob[i], then neither person receives a point.
function compArr(alice , bob){
alicePoints = 0;
bobPoints= 0;
for(i=0; i < 3; i++){
console.log(alice[i]);
console.log(bob[i]);
if(alice[i] < bob[i]) {
bobPoints += 1;
} else if (alice[i] > bob[i]) {
alicePoints += 1;
}
}
return 'AlicePoints = ' + alicePoints + ' ' + 'BobPoints = ' + bobPoints;
}
console.log(compArr([5,6,7],[3,6,10]));
console.log(compArr([32,0,19],[10,7,100]));
console.log(compArr([8,510,32],[9,12,98]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment