GithubHelp home page GithubHelp logo

lab-npm-packages's Introduction

NPM Packages Lab

You will be working with a new package, lodash. Lodash is a modern JavaScript utility library: in other words, it provides a good number of helper functions to assist you in building out your functions.

This goal of this lab is to use the Lodash documentation to assist in building out each function.

Reading documentation and figuring things out on your own can feel uncomfortable and challenging, but it is a critical skill for a developer to gain proficiency with.

Getting Started

  1. Fork and clone this repository.
  2. Navigate to the cloned repository's directory on your command line.
  3. npm install to install the packages for Jest
  4. npm install lodash@4
  5. Open up the repository in VSCode.
  6. Write your answers in index.js
  7. Test your code with npm test

Instructions

You will be building functions for a Yoga Studio to assist with maintaining their records for classes and members.

Each function should use a Lodash method to assist in completing the needed functionality.

Here is an example class object:

const yogaClass = {
  id: "69b0e5d5-df73-4837-94e8-f7a7e4ba2fc5",
  title: "Ashtanga Yoga",
  instructor: "Saffron Sage",
  description:
    "Join Saffron Sage for a dynamic and challenging Ashtanga yoga class. This class is perfect for advanced students and focuses on a set series of poses with breath and movement.",
  durationInMinutes: 90,
  level: "Advanced",
  style: "Ashtanga",
  priceInCents: 2000,
};

The function to write is one that returns just the title and the level. Go to the documentation for Lodash and find the Object section since you are working with an object. Click on various methods until you find one with a description that makes sense for the task.

In this case, _.pick() is a good choice.

function pickTitleAndLevel(classObj) {
  return _.pick(classObj, ["title", "level"]);
}

For this lab, you can combine other methods native to JavaScript or use multiple Lodash methods to build the required functionality. In this next example, the goal is to return an array of objects with the instructor name, class title, and level:

function pickTitlesLevelsAndInstructors(collection) {
  return collection.map((classObj) =>
    _.pick(classObj, ["title", "level", "instructor"])
  );
}

Note that you have some sample data in the data folder. Be sure to reference this data for the shape of the data and you can also use it to try your functions outside of using Jest.

lab-npm-packages's People

Contributors

krafalski avatar

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.