Created
January 18, 2019 05:05
-
-
Save apolopena/10fa62e595deadd6e254df81682036d7 to your computer and use it in GitHub Desktop.
JavaScript: compare array and return a score using array.map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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