Git Product home page Git Product logo

js-looping-and-iteration-map-lab-dumbo-web-062518's Introduction

Map Lab

Problem Statement

The map method is one of the core iterator methods in JavaScript. It's a powerful tool for creating a new collection from an another collection whose members have undergone the change you pass in as an argument.

Objectives

  1. Use map to work with Strings as well as Objects
  2. Use map to perform a set of String transformations
  3. Use map transform a collection of Objects

Use map to work with Strings as well as Objects

This lab contains an array of drivers with various information. We need to write methods using the map method so that Scuber employees can easily change the data into the format their various business rules require. Be sure to run the tests to get a feel for the types of problems this lab is asking you to solve before you start writing JavaScript code.

Use map to perform a set of String transformations

Write lowerCaseDrivers - this function takes an array of drivers, and returns an array of the drivers names in lowercase. Write nameToAttributes - this function takes an array of drivers with their first and last name separated by a space, and returns an array of JavaScript objects with firstName and lastName attributes.

Use map transform a collection of Objects

Write attributesToPhrase - this function takes an array of drivers as JavaScript objects and returns a string saying "<NAME OF DRIVER> is from <HOMETOWN>" for each JavaScript object in the array. Note that between the < and > we are looking for the value stored in the name and hometown object attributes, not the strings "DRIVER" or "HOMETOWN".

Conclusion

While its simple "changing to collect" of each element in a collection is conceptually simple, the power of transforming a collection succinctly means less to type, less to read, and less to get lost in.

Seeing a series of map functions chained together tells readers of the code your intention in a beautifully expressive way.

Further, that map returns an Array means that you can apply filter or reduce immediately after e.g.

students.map( s => !!s.permissionSlip && s.isVegetarian) // Find vegetarians w/ permission slips on file
  .map( s => s.preferredMeal ). // Extract the meal name
  .filter( s => s.match(/curry/i). // Find those who like curry, case-insensitive
  .length;

// => "How many students going on the field trip should we order curry for?"

means you can write terse code that loses little expressivity.

Resources

View Map Lab on Learn.co and start learning to code for free.

js-looping-and-iteration-map-lab-dumbo-web-062518's People

Contributors

jeffkatzy avatar gj avatar lukeghenco avatar jmburges avatar aviflombaum avatar dlchung avatar sgharms avatar

Watchers

 avatar James Cloos 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.