Created
August 18, 2018 14:58
-
-
Save bennycode/c3516e0ed0f6446e283b05c4e18ae98b to your computer and use it in GitHub Desktop.
Compare the Triplets
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
// https://www.hackerrank.com/challenges/compare-the-triplets/problem | |
function compareTriplets(a, b) { | |
const comparisonPoints = [0, 0]; | |
a.forEach((rating, index) => { | |
(rating > b[index]) ? comparisonPoints[0]++ : undefined; | |
(rating < b[index]) ? comparisonPoints[1]++ : undefined; | |
}); | |
return comparisonPoints; | |
} | |
const alicePoints = '17 28 30'.replace(/\s+$/g, '').split(' ').map(aTemp => parseInt(aTemp, 10)); | |
const bobPoints = '99 16 8'.replace(/\s+$/g, '').split(' ').map(aTemp => parseInt(aTemp, 10)); | |
console.log(compareTriplets(alicePoints, bobPoints)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment