Created
September 2, 2016 01:14
-
-
Save rohmanhakim/a9b23a18937082ee945ffa8e2bdd5884 to your computer and use it in GitHub Desktop.
Submission for https://www.hackerrank.com/challenges/compare-the-triplets
This file contains hidden or 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
var a0 = 1; | |
var a1 = 2; | |
var a2 = 3; | |
var b0 = 4; | |
var b1 = 5; | |
var b2 = 6; | |
var ranks = [ | |
[a0,b0], | |
[a1,b1], | |
[a2,b2] | |
]; | |
var compareTriplets = function (ranks,val) { | |
var res = ranks.map(function (rank,index){ | |
return rank[0] > rank[1] ? 1 : rank[0] === rank[1] ? 0 : -1; | |
}).reduce(function (total,rank){ | |
return rank === val ? total + 1 : total + 0; | |
},0); | |
return res; | |
} | |
console.log(compareTriplets(ranks,1) + " " + compareTriplets(ranks,-1)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment