Created
October 8, 2024 06:35
-
-
Save AlvisonHunterArnuero/e3934eedb130f90142d648d26489150b to your computer and use it in GitHub Desktop.
Codewars Challenge: Total Amount Of Points
This file contains 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
// 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment