Work in progress. Codewars Kata Poker Hands
"https://www.codewars.com/kata/5739174624fc28e188000465/train/javascript"
var Result = { "win": 1, "loss": 2, "tie": 3 }
function PokerHand(hand) {
this.hand=hand;
this.handArray=Array.prototype.slice.call(hand);
this.getScore();
}
PokerHand.prototype.getScore=function(){
this.splitHandArray=this.handArray.map(function(e,i,a){
var num=e.slice(0,1);
var suit=e.slice(1);
return {num:num,suit:suit};
});
this.check();
}
PokerHand.prototype.check=function(){
var hands=['rf','sf','fk','fh','fh','f','s','k','tp','op','hc'],fn;
for(var i=0;i<hands.length;i++){
fn='is'+hands[i];
if(this[fn]()){
// sets this_hand_result
break;
}
}
PokerHand.prototype.helpers={
isFlush=function(result,suit){return result.every(function(e){return e.suit===suit;});},
isRoyal=function(result){
return JSON.stringify(result.map(function(e){
return e.num.toString()
}).sort())===JSON.stringify(["K","Q","J","10","A"].sort());
}
}
PokerHand.prototype.isrf=function(){
var result=this.splitHandArray;
var suit=result[0].suit;
var isFlush=this.helpers.isFlush(result,suit);
var isRoyal=this.helpers.isFlush(result);
if(isFlush && isRoyal){
this.hand_result='rf';
return;
}
return false;
};
PokerHand.prototype.issf=function(){};
PokerHand.prototype.isfk=function(){};
PokerHand.prototype.isfh=function(){};
PokerHand.prototype.isf=function(){};
PokerHand.prototype.iss=function(){};
PokerHand.prototype.isk=function(){};
PokerHand.prototype.istp=function(){};
PokerHand.prototype.isop=function(){};
PokerHand.prototype.ishc=function(){};
PokerHand.prototype.compareWith = function(hand){
return Result.tie;
}