Exercise 1: Back-End of the E-sport Analysis Platform

Project Pitch

In this exercise, you will develop the core logic (the back-end) of an e-sport analysis platform named "Esport Vision." You will learn how to structure data with classes and manipulate it with modern array methods to manage a match schedule.

Context / Scenario

You are joining the startup "Esport Vision" as a developer. Your first mission is to build the prototype of the system that will manage and analyze upcoming matches from the French League of Legends (LFL) and Valorant (VCT) leagues for the year 2025. The reliability of the data and the relevance of the analysis are crucial for the platform's success.


Starting Data

Copy and paste the following table at the beginning of your JavaScript file. It represents the schedule of upcoming matches that your system will need to manage.

const matchSchedule = [
  {
    id: 'LFL_KC_SLY',
    game: 'League of Legends',
    competition: 'LFL',
    teamA: 'Karmine Corp',
    teamB: 'Solary',
    probabilityA: 0.65, // 65% chance for KC
    status: 'Upcoming'
  },
  {
    id: 'VCT_VIT_M8',
    game: 'Valorant',
    competition: 'VCT EMEA',
    teamA: 'Team Vitality',
    teamB: 'Mandatory',
    probabilityA: 0.55, // 55% chance for Vitality
    status: 'Upcoming'
  },
  {
    id: 'LFL_GO_BDS',
    game: 'League of Legends',
    competition: 'LFL',
    teamA: 'Gentle Mates',
    teamB: 'BDS Academy',
    probabilityA: 0.48, // 48% chance for M8, so BDS is favored
    status: 'Upcoming'
  },
  {
    id: 'LFL_KC_M8',
    game: 'Valorant',
    competition: 'VCT EMEA',
    teamA: 'Karmine Corp',
    teamB: 'Mandatory',
    probabilityA: 0.52,
    status: 'Upcoming'
  }
];

5. Steps to Complete

Step 1: Model the data with the Match class

The goal is to create a class for our match objects to ensure a consistent data structure.

  1. Create a Match class.
  2. Its constructor should accept and initialize the following properties: id, game, competition, teamA, teamB, probabilityA, and status.
  3. Add a getFavorite() method to this class. This method takes no parameters and should return the name of the team with the highest probability of winning. If probabilityA is greater than 0.5, it returns teamA; otherwise, it returns teamB.

Step 2: Create the manager with the Platform class

This class will be the heart of our system; it will manage all the matches.

  1. Create a Platform class.
  2. Its constructor should accept a name and initialize a matches property with an empty array.
  3. Implement the loadMatches(matchesToLoad) method. This method takes an array of objects (like matchSchedule) as a parameter, and for each object, it must create a new instance of the Match class and add it to the this.matches array.
  4. Implement the displaySchedule() method. Using a loop (forEach), this method should display the summary of each match in the console in a readable format. For example:
    [LFL] Karmine Corp vs. Solary - Game: League of Legends

Step 3: Implement analysis functionalities

Now, add methods to the Platform class to allow for data analysis.

  1. getMatchesByGame(game):

    • Use the .filter() method on the this.matches array.
    • This method should return a new array containing only the matches corresponding to the game passed as a parameter (e.g., "Valorant").
  2. getRiskyMatches():

    • Use the .filter() method.
    • This method should return the matches considered "close," that is, those where the favorite's probability of winning is low. Return the matches where probabilityA is between 0.45 and 0.55.
  3. getMatchById(id):

    • Use the .find() method.
    • This method should find and return the match instance corresponding to the provided ID.

Step 4: Practical Application

At the end of your file, write the script that will use your classes to make the system work.

  1. Create an instance of your Platform class named esportVision.
  2. Use loadMatches() to add the data from matchSchedule to it.
  3. Call displaySchedule() to verify that everything is loaded correctly.
  4. Test each of your analysis methods (getMatchesByGame, getRiskyMatches, getMatchById) and display their results in the console with clear console.log statements to see what each method returns.

6. Going Further (Bonus)

If you are finished and want to go further, try implementing these features:

  • Add a simulateResult(matchId) method to the Platform. It should find the match, use Math.random() and the probabilities to determine a winner, then change the match status to "Completed" and add a result property with the winner's name.
  • Add a getTeamStats(teamName) method. It should return an object containing the number of matches played by the team and its win rate (based on the simulated matches).

7. WARNING! ANY CHEATING WILL BE SEVERELY PUNISHED!

People who submit the same code will simply share the grade. A 10/20 will become a 5/20 for two, or a 3/20 for three people who tried to cheat! It's of no interest, neither to you nor to me!