Giter Site home page Giter Site logo

javascript-map-lab-v-000's Introduction

JavaScript Map Lab

Overview

The .map() function allows us to transform elements in an array from one value to another, we can take a look at some practical examples. There's no need to implement your own map() function, since we can readily use the Array.prototype.map() method.

Uncovering alliances

Decepticons

Imagine we're a top-end cyber researcher for DARPA. The military has given us a list of robots. We also have a manifest of all known Decepticon robot names. Our job is to go through the list of robots, and set their alliance accordingly.

  • Create a new variable called sortedRobots;
  • The value of this variable is the mapped robots array;
  • Return each robot object with the alliance filled in with either an 'autobot' or 'decepticon' string.
  • To figure out a robot's alliance, check if their name exists in the knownDecepticons array.
  • (Hint: use Array.prototype.includes to easily check if an element exists in an array.)
  • The original objects in the robots array must not be modified, so be sure to use Object.assign()

The White Stripes

The coolest zebra.

A zebra without stripes is just a silly looking horse. We have a zebraStripes array that represents the stripes of our dancing friend up here, but the stripes don't have any color yet. Let's fix that!

  • Create a new variable called coloredZebraStripes;
  • The value of this variable is the mapped zebraStripes array;
  • Return each stripe object with the stripe filled in with either a 'black' or 'white' string.
  • A stripe is black when the stripe's index is even, and it's white if a stripe's index is odd.
  • (Hint: the callback we pass to .map() takes more than one parameter)
  • The original objects in the zebraStripes array must not be modified, so be sure to use Object.assign()

Resources

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

javascript-map-lab-v-000's People

Contributors

pletcher avatar annjohn avatar thomastuts avatar dakotalmartinez avatar mk-etlinger avatar alpha-convert avatar

Watchers

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