winningCard.js

    0

    0

    The solution function loops through all the cards and calculates the highest card. If the card that is being processed is the highest card, then the function basically returns this card. If there is a tie for the highest card, then the function tries to determine the winner by looking at the length of the list of NoDuplicate cards and then comparing the highest one to the winner variable.

    
      function solution(cards) {
    // write your solution here
    let winner=-1
    cards.forEach(function(card){
    let NoDuplicate= (card.filter((el, _, card) => {
    return card.filter(el2 => el2 === el).length === 1
    }))
    let highCard=Math.max(...NoDuplicate)
    if(winner<highCard){
    winner=highCard;
    }
    })
    return winner;
    }
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.