In this lab, you will develop a JavaScript project that involves building and iterating over nested objects and arrays. This lab will help you develop foundational skills in Object Iteration, Array Iteration, and Array Looping by implementing functions to extract data from complex objects. You’ll use these techniques to build out several small functions that access and manipulate data for a fictional basketball game stats tracker.
Pre-written test cases are provided in indexTest.js
, and your task is to implement the required functions in index.js
to ensure all tests pass when run locally using Jest.
You are a developer working for a sports tech company. Your current project is to implement features for a live NBA game stats tracker. The gameObject
function provides data for two teams, including team names, colors, and stats for each player. Your task is to use Object and Array Iteration to retrieve specific player stats, team information, and more.
- Code Editor: Visual Studio Code (or your preferred editor)
- Node.js: To execute JavaScript locally
- Jest: For running test cases
- Go to the GitHub repository for this lab.
- Fork the repository to your GitHub account.
- Clone the forked repository to your local machine:
git clone https://github.com/your-username/lab-pulling-it-all-together-with-object-and-array-iteration-in-javascript.git
- Navigate into the project directory:
cd lab-pulling-it-all-together-with-object-and-array-iteration-in-javascript
- Install the required dependencies:
npm install
The gameObject
function is already provided and includes nested objects representing two teams. Your task is to implement the following functions in index.js
:
-
numPointsScored(playerName)
Returns the points scored by the given player. -
shoeSize(playerName)
Returns the shoe size of the given player.
-
teamColors(teamName)
Returns an array of the team’s colors. -
teamNames()
Returns an array of both team names.
-
playerNumbers(teamName)
Returns an array of jersey numbers for the given team. -
playerStats(playerName)
Returns an object containing all stats for the given player.
bigShoeRebounds()
Finds the player with the largest shoe size and returns their number of rebounds.
To ensure your implementation is correct, pre-written tests are provided in indexTest.js
. These tests are configured to verify your functions and are based on the data structure in gameObject
.
-
Run the following command to execute the tests:
npm test
-
Review the test results in your terminal. Tests that pass will be marked in green, while failing tests will show error messages with details about the failure.
-
Debug your code and fix any issues to ensure all tests pass successfully.
Run ESLint to ensure your code adheres to best practices:
npx eslint index.js
Fix any issues reported and refactor your code for readability and maintainability.
The helpers.js
file is included to set up a testing environment using additional libraries like Chai and Sinon. It ensures compatibility and provides utilities for more advanced testing scenarios.
The indexTest.js
file contains the test suite for this lab. It includes tests for all the functions you need to implement. Below is a sample of the test cases:
describe('Basketball Stats', function () {
describe('numPointsScored', function () {
it('should return points scored by a player', function () {
expect(numPointsScored('Alan Anderson')).to.equal(22);
expect(numPointsScored('Ben Gordon')).to.equal(33);
});
});
describe('shoeSize', function () {
it('should return shoe size of a player', function () {
expect(shoeSize('Alan Anderson')).to.equal(16);
expect(shoeSize('Ben Gordon')).to.equal(15);
});
});
// Additional tests for other functions...
});
Your grade will be determined based on your ability to pass all the provided test cases and the quality of your code. Make sure you have:
- Successfully implemented all required functions.
- Passed all test cases in
indexTest.js
using Jest. - Ensured your code is clean, modular, and adheres to best practices by running ESLint.
- Use
console.log()
strategically during development for debugging, but remove or comment them out before submission. - Validate your functions against edge cases (e.g., a player or team not existing in the dataset).
- Focus on clean, modular code—grading includes an assessment of code readability and maintainability.