Code Monkey home page Code Monkey logo

unit-1-js-assessment's Introduction

Nested Data Exercises

๐Ÿ’ช 10+ Practice Challenges: Nested Objects & Arrays

This challenge will test your ability to work with nested Objects and Arrays.

Uses real-world 'inspired' data.

If you are experienced on this topic, expand the "๐Ÿ’ก Challenge Yourself!" section (following the instructions.)

Index

Instructions

Task: Complete the 10+ functions in index.js and pass all tests specified in test/index.test.js โœ…

The difficulty increases as you progress.

Before you begin coding, review test data below

  1. getName(character) -> Luke Skywalker
  2. getFilmCount(character) -> 5
  3. getFirstStarshipName(character) -> X-wing
  4. getSummary(character) -> Luke Skywalker, 172cm, 77kg. Featured in 5 films.
  5. getVehiclesCostInCreditsSumTotal(character) -> 8000
  6. getStarshipPassengerAndCrewSumTotal(character) -> 27
  7. getNthFilm(character, filmNumber) filmNumber=1 -> A New Hope
  8. getCargoCapacityTotal(character) -> 80124
  9. getFastestStarshipName(character) -> X-wing
  10. getLargestCargoStarshipModelName(character) -> Lambda-class T-4a shuttle
  11. getSlowestVehicleOrStarshipName(character) -> Imperial Speeder Bike

Stretch

๐Ÿ’ก Challenge Yourself! (expand for stretch tips)
  • Research & use different patterns. (Destructuring, move common code into reusable helper methods, functional programming techniques)
  • Trade completed code with a peer:
    • Pair program: Take turns (30-60 min.) working through a refactor. Talk through & optimize as needed.
    • Trade code for feedback! (Example format: 3&1, 3 things that you liked and 1 to improve.)
  • Time yourself. See if you can beat your own time starting over. Speed run!
  • See how many tests you can pass/complete before Googling or asking for help.
  • When you're finished, refactor & improve readability. Write up why it is improved.

Get Started

3 options are included below.

The CodeSandbox option is fast & highly recommended.

1. Fastest Option

LAUNCH ON CODESANDBOX ๐Ÿš€

2. Local Setup Instructions: From Command Line
  1. Fork & clone to your local computer
  2. cd into your newly cloned repository
  3. Install using npm
  4. Run test command
git clone <insert your git clone url here>
cd <repo folder name>
npm install
npm run test:watch
#####
### Or without fs watching:
# npm test

NOTE: In local development, use the file watcher command: npm run test:watch.

3. Local Setup Instructions: Run Tests in Browser
  1. Fork & clone to your local computer
  2. cd into your newly cloned repository
  3. Install and Start using npm
git clone <insert your git clone url here>
cd <repo folder name>
npm install
npm start

Data

Example data your code will be tested against.

// Complete Test Data Object (credit: https://SWAPI.co)
// Side note: Yes Star Wars ๐Ÿค“ purists. It's a bit out of date. Talk to SWAPI about it.
// Focus & follow instructions above. ๐Ÿค–
{
  "name": "Luke Skywalker",
  "height": "172",
  "mass": "77",
  "hair_color": "blond",
  "skin_color": "fair",
  "eye_color": "blue",
  "birth_year": "19BBY",
  "homeworld": "Tatooine",
  "films": [
    "A New Hope",
    "The Empire Strikes Back",
    "Return of the Jedi",
    "Revenge of the Sith",
    "The Force Awakens"
  ],
  "species": [
    "Human"
  ],
  "vehicles": [
    {
      "name": "Snowspeeder",
      "model": "t-47 airspeeder",
      "manufacturer": "Incom corporation",
      "cost_in_credits": null,
      "length": "4.5",
      "max_atmosphering_speed": "650",
      "crew": 2,
      "passengers": 0,
      "cargo_capacity": "10"
    },
    {
      "name": "Imperial Speeder Bike",
      "model": "74-Z speeder bike",
      "manufacturer": "Aratech Repulsor Company",
      "cost_in_credits": "8000",
      "length": "3",
      "max_atmosphering_speed": "360",
      "crew": 1,
      "passengers": 1,
      "cargo_capacity": "4"
    }
  ],
  "starships": [
    {
      "name": "X-wing",
      "model": "T-65 X-wing",
      "manufacturer": "Incom Corporation",
      "cost_in_credits": 149999,
      "length": "12.5",
      "max_atmosphering_speed": "1050",
      "crew": 1,
      "passengers": 0,
      "cargo_capacity": "110",
      "consumables": "1 week",
      "hyperdrive_rating": "1.0",
      "MGLT": "100",
      "starship_class": "Starfighter"
    },
    {
      "name": "Imperial shuttle",
      "model": "Lambda-class T-4a shuttle",
      "manufacturer": "Sienar Fleet Systems",
      "cost_in_credits": 240000,
      "length": "20",
      "max_atmosphering_speed": "850",
      "crew": 6,
      "passengers": 20,
      "cargo_capacity": "80000",
      "consumables": "2 months",
      "hyperdrive_rating": "1.0",
      "MGLT": "50",
      "starship_class": "Armed government transport"
    }
  ],
  "created": "2014-12-09T13:50:51.644000Z",
  "edited": "2014-12-20T21:17:56.891000Z",
  "url": "https://swapi.co/api/people/1/"
}

Hints

Helpful tips & reminders ๐Ÿ”Ž

  • If you get stuck, it can help to review the test script test/index.test.js.
  • Critical: Don't make assumptions about input data types. (Convert/handle Numbers & null)
    • Convert number strings into actual numbers with built-in functions parseInt, parseFloat, Number, etc.
  • Ensure your functions return somethingUseful.
  • Make sure you understand the requirements. All the words used? Try list the steps in comments first.
  • Don't forget the source data uses snake_case naming.
  • Pay close attention to array vs. object syntax (vehicles[0].name vs. character.vehicles.)
  • Some of the functions include detailed instructions.
  • You might have to infer the desired fields. Carefully read the description and function name (description included above the function.)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.