Skip to content

Instantly share code, notes, and snippets.

@apolopena
Created January 18, 2019 05:05
Show Gist options
  • Save apolopena/10fa62e595deadd6e254df81682036d7 to your computer and use it in GitHub Desktop.
Save apolopena/10fa62e595deadd6e254df81682036d7 to your computer and use it in GitHub Desktop.
JavaScript: compare array and return a score using array.map
function compareTriplets(a, b) {
let score1, score2, iter;
score1 = score2 = iter = 0;
a.map(item => {
if (item > b[iter]) {
score1++;
}
if ( item < b[iter]) {
score2++;
}
iter++;
});
return [score1, score2];
}
console.log(compareTriplets([1,2,3], [6,1,2]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment