Alex is a young entrepreneur who is out to assemble his own football team to enter the FPL. Ambitious much? Well, he seems to have the resources to do it though. He has collected data on players across various teams. He now needs to arrange this data in order to make sense of it. He needs an application that will help him compare and contrast the abilities of different players.
Alas, for all the money in the world, he can't find a decent programmer to help him with this task. He's designed the front end of the application, and it looks great. He needs YOU to help him code the functionalities in the back end, though. Go to the src/app.js
file and complete all the unfinished code to propel this young man's football dream.
Here is the boilerplate link of the lab. Fork the project and get started with the lab.
The src/data.js
contains an array of 250 players. We are talking about the array of 25 objects containing the info about each player. Here is one example of how the data will be displayed:
{
name: 'Ashley Young',
age: 34,
debut: 2011,
team: 'Manchester Utd',
position: 'Defender',
country: 'England',
awards: [
{
name: "Golden Foot",
year: 2015
}
]
}
Ohh yes! We have our beloved tests, and you already know how this works. Open the SpecRunner.html
file on your browser and start coding to pass the test. Remember to focus on one test at a time and read carefully the instructions to understand what you have to do.
Every team starts off with a manager. We need someone to take care of them when Alex isn't around. Create a function createManager()
that gets the manager's details managerName, managerAge, currentTeam, trophiesWon
in the same order, and return an array with the manager's details.
The coach has prepared a plan of action for the team. He has the formation ready and will provide us with an array [defender, midfield, forward]
. He will give us the numbers, and we'll need to print that layout on our screen so that we know who to pick (for instance, how many midfielders do we need?). Create a function createFormation()
that returns an object with the data and keys in the order given in the array.
Alex needs to know when a player debuted. Alex was just going through some astrological facts and had discovered that there are specific years where lady luck favored all. He believes that selecting those players would be great for his team. Create a function filterByDebut()
which takes year
as an argument and returns an array of player objects that debuted in the given year.
We've already decided on the team formation. Now we need to filter players based on their position. This would help Alex decide who goes where. Create a function filterByPosition()
which takes position
as an argument and returns an array of player objects that play in that position.
Who doesn't want a player with multiple medals and trophies in his closet? Alex wants you to retrieve data on players who have won a specific award. Create a function filterByAward()
which takes awardName
as an argument and returns an array of player objects that who have won that award.
Now that we've got players that have won an award, we need to find out how many times they've won a specific award. The more, the merrier. Create a function filterByAwardxTimes()
which takes awardName, noOfTimes
as arguments and returns an array of player objects that have won a specific ward a given number of times.
Alex prefers some countries over others. That doesn't mean he's willing to ignore achievements. Why? Well, let's not get into details. Create a function filterByAwardxTimes
which takes awardName, country
as arguments and returns an array of player objects that have won a specific award and belong to the given country.
Alex is getting very meticulous with his selection criteria. He believes youth overpower age, but they should have won a certain number of awards and belong to his favorite team. Create a function filterByNoOfAwardsxTeamxAge()
which takes noOfAwards, team, age
as arguments and returns an array of player objects that have won at least the given number of awards, belong to a specific team and are younger than mentioned age.
You know what they say, "Age before beauty". Alex wants you to display the players in order of age, oldest first. He wants to pick some more experienced players than what we currently have in our roster. Create a function SortByAge()
which returns an array of player objects in descending order of their age.
Retrieve players of a specific team. Then, display them in descending order of the number of awards won by each player. Create a function FilterByTeamxSortByNoOfAwards()
which takes team
as an argument and returns an array of player objects.
Find out players who have won a certain award a given number of times. They must also belong to Alex's favorite country. Sort them in good old-fashioned alphabetical order. Create a function SortByNamexAwardxTimes()
which takes awardName, noOfTimes, country
as arguments and returns an array of player objects.
Time to get things finally sorted out. So, two things - one, sort players older than a given age in alphabetical order. Also, sort their awards based on reverse chronological order. Create a function SortByNamexOlderThan()
which takes an argument age
and returns an array of player objects.
Host your completed lab project in GitHub and submit your project repository link in this form.
Happy Coding ❤️