Skip to content

Instantly share code, notes, and snippets.

@bennycode
Created August 18, 2018 14:58
Show Gist options
  • Save bennycode/c3516e0ed0f6446e283b05c4e18ae98b to your computer and use it in GitHub Desktop.
Save bennycode/c3516e0ed0f6446e283b05c4e18ae98b to your computer and use it in GitHub Desktop.
Compare the Triplets
// 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