Coder Social home page Coder Social logo

rest-api-total-goals-by-a-team's Introduction

the REST API contains information about football matches.
The provided API allows querying matches by teams and year. Your task is to get the total number of goals scored by a given team in a given year.

To access a collection of matches, perform GET requests to

https://jsonmock.hackerrank.com/api/football_matches?year=<year>&team1=<team>&page=<page>

https://jsonmock.hackerrank.com/api/football_matches?year=<year>&team2=<team>&page=<page>

where <year> is the year of the competition, <team> is the name of the team, and <page> is the page of the results to request. The results might be divided into several pages. Pages are numbered from 1.

 

Notice that the above two URLs are different. The first URL specifies the team1 parameter (denoting the home team) while the second URL specifies the team2 parameter (denoting the visiting team). Thus, in order to get all matches that a particular team played in, you need to retrieve matches where the team was the home team and the visiting team.

 

For example, a GET request to

https://jsonmock.hackerrank.com/api/football_matches?year=2011&team1=Barcelona&page=2

returns data associated with matches in the year 2011, where team1 (the home team) was Barcelona, on the second page of the results.

 

Similarly, a GET request to

https://jsonmock.hackerrank.com/api/football_matches?year=2011&team2=Barcelona&page=1

returns data associated with matches in the year 2011 where team2 (the visiting team) was Barcelona, on the first page of the results.

 

The response to such a request is a JSON with the following 5 fields:

  • page: The current page of the results.

  • per_page: The maximum number of matches returned per page.

  • total: The total number of matches on all pages of the results.

  • total_pages: The total number of pages with results.

  • data: An array of objects containing matches information on the requested page.

 

Each match record has several fields, but in this task only the following 4 are relevant:

  • team1: a string denoting the name of the first team in the match

  • team2: a string denoting the name of the second team in the match

  • team1goals: a string denoting the number of goals scored by team1 in the match

  • team2goals: a string denoting the number of goals scored by team2 in the match

 

Function Description

Complete the function getTotalGoals in the editor below.

 

getTotalGoals has the following parameters:

    string team: the name of the team

    int year: the year of the competition

 

The function must return an integer denoting the total number of goals scored by the given team in all matches in the given year that the team played in.

 

Input Format For Custom Testing

In the first line, there is a string, team.

In the second line, there is an integer, year.

Sample Case 0

Sample Input For Custom Testing

Barcelona
2011

Sample Output

35

Explanation

The team is Barcelona and the year is 2011. When we fetch all the matches that Barcelona played in the year 2011, we find that they scored a total of 35 goals, which is the required answer.

rest-api-total-goals-by-a-team's People

Contributors

khalil-elf441 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.