Last active
August 16, 2019 22:05
-
-
Save OlukaDenis/de81d18a0ee1d5b94f7a5b210d6349b2 to your computer and use it in GitHub Desktop.
Solution for HackerRank > Algorithms > Warmup > Compare the Triplets. Visit https://www.hackerrank.com/challenges/compare-the-triplets/problem?h_r=next-challenge&h_v=zen
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
/* | |
This is the easiest method | |
Hope it helps | |
*/ | |
function compareTriplets(a, b) { | |
let aliceScore = 0 | |
let bobScore = 0 | |
let result = [0, 0] | |
for (let i = 0; i<a.length; i++){ | |
if (a[i] > b[i]) { | |
aliceScore += 1 | |
result.splice(0,1,aliceScore) | |
} else if (a[i] < b[i]) { | |
bobScore += 1 | |
result.splice(1,1,bobScore) | |
} | |
} | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment