Our football team finished the championship. The result of each match look like "x:y". Results of all matches are recorded in the collection.
For example: ["3:1", "2:2", "0:1", ...]
Write a function that takes such collection and counts the points of our team in the championship. Rules for counting points for each match:
if x>y - 3 points
if x<y - 0 point
if x=y - 1 point
Notes:
there are 10 matches in the championship
0 <= x <= 4
0 <= y <= 4
function points(games) {
return games.map(el => (el[0] > el[2]) ? 3 : (el[0] === el[2]) ? 1 : 0).reduce((sum, cur) => sum + cur)
}
오늘 배운 메소드를 모두 합쳐서 구현해보았다... .map
으로 각 요소에 삼항연산자로 if
else if
else
를 만들어 배열을 점수로 만들고, .reduce
로 합산해 주었다. 😁