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 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