PLEASE FIX THE CODE
const suits = ["♥", "♦", "♣", "♠"];
const ranks = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"];

class Card {
  constructor(suit, rank) {
    this.suit = suit;
    this.rank = rank;
  }
  
  toString() {
    return `${this.rank}${this.suit}`;
  }
}

function determineWinners(playerHands, boardCards) {
  const allHands = playerHands.map((hand) => [...hand, ...boardCards]);
  const bestHands = allHands.map((hand) => getBestHand(hand));
  const maxRank = Math.max(...bestHands.map((hand) => hand.rank));

  return bestHands.reduce((winners, hand, index) => {
    if (hand.rank === maxRank) {
      winners.push({
        playerId: index,
        winningCombinationId: hand.combination.id,
        winningCards: hand.cards,
      });
    }
    return winners;
  }, []);
}

function getBestHand(cards) {
  const combinations = [
    RoyalFlush,
    StraightFlush,
    FourOfAKind,
    FullHouse,
    Flush,
    Straight,
    ThreeOfAKind,
    TwoPairs,
    Pair
  ];

  for (const Combination of combinations) {
    const result = Combination.test(cards);
    if (result != null) {
      return { rank: Combination.rank, combination: result.combination, cards: result.cards };
    }
  }
}

class Combination {
  constructor(name, id, rank) {
    this.name = name;
    this.id = id;
    this.rank = rank;
  }

  static test(cards) {}
}

class TwoPairs extends Combination {
  constructor() {
      super("Two Pairs", 2, 2);
  }

	static test(cards){
		let pairsArr = [];
		for(let i=0 ; i<cards.length-1; i++){
			if(cards[i].rank === cards[i+1].rank){
				pairsArr.push([cards[i], cards[i+1]]);
			}
		}

		if(pairsArr.length<2) {
			return null;
	   }

	    let pair1= pairsArr[0];
	    let pair2= pairsArr[1];

    	let remainingCards=[];

	    for(let i=0; i<cards.length;i++){
		    if(cards[i] != pair1[0] && cards[i] != pair1[1] &&
		      cards[i] != pair2[0] && cards[i]!=pair2[1])  {
		         remainingCards.push(cards[i]);
		     }
	     }

         if(remainingCards.length === 0) { return null;}

           let sortedRemainingCards = remainingCards.sort((a,b)=> b.rank - a.rank);

          for (let card of sortedRemainingCards){
            if(pair1.length < 4 && card.rank == pair1[0].rank){
                pair1 =[...pair1,card];
            }else if(pair2.length < 4 && card.rank == pair2[0].rank){
                pair2 =[...pair2,card];
            } else if(pair2.length == 4){
                 break;
            }
        }

         if(pair1.length!==4 || pair2.length!==4 ) {return null;}

         return { combination: this, 
                  cards:[...pair1,...pair2.slice(-2)]};
     }   	 		
}

function testTwoPairs() {
  const twoPairs = new TwoPairs();

  // Test with two separate pairs
  const handOne = [
    new Card("Spades", "J"),
    new Card("Clubs", "J"),
    new Card("Hearts", "K"),
    new Card("Diamonds", "K"),
    new Card("Spades", "A")
  ];
  
  const expectedOutputOne = {
      combination: twoPairs, 
      cards:[new Card("Hearts", "K"), new Card("Diamonds", "K"), new Card("Spades", "J"), new Card("Clubs", "J")]
  };
  
  const actualOutputOne = TwoPairs.test(handOne);

  console.log('Test with two separate pairs');
  console.log(actualOutputOne);
  console.log(JSON.stringify(actualOutputOne) === JSON.stringify(expectedOutputOne));

  // Test with three pairs
  const handTwo = [
    new Card("Spades", "3"),
    new Card("Clubs", "3"),
    new Card("Hearts", "K"),
    new Card("Diamonds", "K"),
    new Card("Spades", "K")
  ];
  
   const expectedOutputTwo = {
     combination: twoPairs, 
     cards:[new Card("K","♠"),new Card("K","♦"),new Card(3,"♠"),new Card(3,"♣")]
   };
  
   const actualOutputTwo = TwoPairs.test(handTwo);

   console.log('Test with three pairs');
   console.log(actualOutputTwo);
   console.log(JSON.stringify(actualOutputTwo) === JSON.stringify(expectedOutputTwo));

  // Test with no pair
  const handThree = [
    new Card("Spades", "A"),
    new Card("Clubs", "2"),
    new Card("Hearts", "5"),
    new Card("Diamonds", "9"),
    new Card("Spades", "Q")
  ];

 const expect=(TwoPairs.test(handThree))==(null)
 console.log('Test with no pair',expect)
}

testTwoPairs();