Created
July 14, 2020 16:59
-
-
Save mgamini/a29978f463606e11cd15f650c7e5b8bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Most team sports have a depth chart (a ranking of each player) for each position they have. For Example in NFL: Ben Roethlisberger is listed as the starting QB and first on the QB depth chart. Landry Jones, his backup is listed as the 2nd person on that depth chart. We want to implement functionality that will manage these depth charts. | |
Data Model | |
Assume player objects look like this. Note that players can be on the depth chart for positions that are not their own. | |
{ | |
"player_id": 1, | |
"name": "Bob", | |
"position": "WR" | |
} | |
Problems to solve (Not all need Completed): | |
1.) Write the method: | |
addPlayerToDepthChart(player, position, position_depth) | |
This method adds a player to a depth chart for a given position (at a specific spot). If no position_depth is provided, then add them to the end of the depth chart for that position. If you are entering two players into the same slot, the last player entered gets priority and bumps the existing player down a depth spot. | |
2.) Write the method | |
removePlayerFromDepthChart(player, position) | |
This method removes a player from the depth chart for a position | |
3.) If the code does not support it already, how would you alter your code to ensure the same player can not be added to the depth chart multiple times? | |
4.) If the code does not support it, how would you alter your code so that players can be added to depth chart in reverse order and have gaps? (I might know who my 3rd string QB is gonna be but could be still deciding between 1st and 2nd so I wouldn't add them to the depth chart yet.) | |
5.) Write the method: | |
getFullDepthChart() | |
The method should display the depth chart in a human readable fashion. Just returning the string is fine too. Ex: | |
QB Depth Chart - 1 : Ben, 2: Bob | |
6.) Write the method | |
getPlayersUnderPlayerInDepthChart(player, position) | |
For a given player, this method finds all players below them on the depth chart. | |
7.) How would you alter/organize your code to support multiple sports? | |
n^2 solutions | |
Example: | |
var bob = { "player_id": 1, "name": "Bob" } | |
var alice = { "player_id": 2, "name": "Alice" } | |
var charlie = { "player_id": 3, "name": "Charlie"} | |
addPlayerToDepthChart(bob, "WR", 0); | |
addPlayerToDepthChart(alice, "WR", 0); | |
addPlayerToDepthChart(charlie, "WR", 2); | |
addPlayerToDepthChart(bob, "KR"); | |
getFullDepthChart(); | |
/* | |
Output: | |
WR: [2, 1, 3], | |
KR: [1] | |
*/ | |
getPlayersUnderPlayerInDepthChart(alice, "WR"); | |
/* | |
Output: | |
[1,3] | |
*/ | |
Please implement the 4 use cases above for: | |
NFL supporting positions (QB, WR, RB, TE, K, P, KR, PR) | |
MLB supporting positions (SP, RP, C, 1B, 2B, 3B, SS, LF, RF, CF, DH). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment