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.
- Create a
Match
class. - Its
constructor
should accept and initialize the following properties:id
,game
,competition
,teamA
,teamB
,probabilityA
, andstatus
. - 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. IfprobabilityA
is greater than 0.5, it returnsteamA
; otherwise, it returnsteamB
.
Step 2: Create the manager with the Platform
class
This class will be the heart of our system; it will manage all the matches.
- Create a
Platform
class. - Its
constructor
should accept aname
and initialize amatches
property with an empty array. - Implement the
loadMatches(matchesToLoad)
method. This method takes an array of objects (likematchSchedule
) as a parameter, and for each object, it must create a new instance of theMatch
class and add it to thethis.matches
array. - 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.
-
getMatchesByGame(game)
:- Use the
.filter()
method on thethis.matches
array. - This method should return a new array containing only the matches corresponding to the game passed as a parameter (e.g., "Valorant").
- Use the
-
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 between0.45
and0.55
.
- Use the
-
getMatchById(id)
:- Use the
.find()
method. - This method should find and return the match instance corresponding to the provided ID.
- Use the
Step 4: Practical Application
At the end of your file, write the script that will use your classes to make the system work.
- Create an instance of your
Platform
class namedesportVision
. - Use
loadMatches()
to add the data frommatchSchedule
to it. - Call
displaySchedule()
to verify that everything is loaded correctly. - Test each of your analysis methods (
getMatchesByGame
,getRiskyMatches
,getMatchById
) and display their results in the console with clearconsole.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 thePlatform
. It should find the match, useMath.random()
and the probabilities to determine a winner, then change the match status to "Completed" and add aresult
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!