Skip to content

Instantly share code, notes, and snippets.

@OlukaDenis
Last active August 16, 2019 22:05
Show Gist options
  • Save OlukaDenis/de81d18a0ee1d5b94f7a5b210d6349b2 to your computer and use it in GitHub Desktop.
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 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