Skip to content

Instantly share code, notes, and snippets.

@AlvisonHunterArnuero
Created October 8, 2024 06:35

Revisions

  1. AlvisonHunterArnuero created this gist Oct 8, 2024.
    15 changes: 15 additions & 0 deletions totalAmountOfPoints.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    // CODEWAR CHALLENGE: Total amount of points
    // Kata Link: https://www.codewars.com/kata/5bb904724c47249b10000131

    const points = (gamesResultsArr) =>
    gamesResultsArr.reduce((totalPoints, gameResults) => {
    const [team1, team2] = gameResults.split(":").map(Number);
    if (team1 === team2) return totalPoints + 1;
    return totalPoints + (team1 > team2 ? 3 : 0);
    }, 0);

    console.log(points(["1:0","2:0","3:0","4:0","2:1","3:1","4:1","3:2","4:2","4:3"])); // 30
    console.log(points(["1:1","2:2","3:3","4:4","2:2","3:3","4:4","3:3","4:4","4:4"])); // 10
    console.log(points(["0:1","0:2","0:3","0:4","1:2","1:3","1:4","2:3","2:4","3:4"])); // 0
    console.log(points(["1:0","2:0","3:0","4:0","2:1","1:3","1:4","2:3","2:4","3:4"])); // 15
    console.log(points(["1:0","2:0","3:0","4:4","2:2","3:3","1:4","2:3","2:4","3:4"])); // 12