GithubHelp home page GithubHelp logo

dkennell / javascript-reduce-lab-v-000 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from learn-co-students/javascript-reduce-lab-v-000

0.0 1.0 0.0 12 KB

License: Other

HTML 21.10% JavaScript 78.90%

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

JavaScript Reduce Lab

Overview

This lab will give you practice using a reduce function and iterating over different abstractions.

Introduction

By now, we know that .reduce() is nothing more than a function to reduce an array to another value, such as a number, a string, or another array. This allows us to easily count word occurrences, calculate a total sum of product prices, and so on.

In this lab, we'll focus on flexing those reduce() muscles! Remember โ€” Array.prototype.reduce() takes two arguments: the callback and the initialValue.

Technologic

Pat and Dave are hard at work in the battery factory. They've assembled several batches of batteries today. Let's count how many assembled batteries we ended up with, while they go out for an oil change.

  • Create a new variable called totalBatteries which is the sum of all of the battery amounts in the batteryBatches array. Naturally, use .reduce() for this!

Perfecting the monologue

Walter White

One of the most iconic scenes in the television show "Breaking Bad" is where Walter White reveals to his wife, Skyler, how deeply entrenched he is in the meth business. Writing this monologue must have been a pain. For future episodes, it would be great if the show's writer could get an overview of the amount of sentences mapped by word count.

For example, say we have these three lines:

const lines = [
  'Who are you talking to right now?',
  'Who is it you think you see?',
  'Do you know how much I make a year?',
];

Our output would look like this:

{ '7': 2, '9': 1 }

This output can be interpreted as: 'We have two sentences with 7 words, and one sentence with 9 words'. That should help the writer to write even more dramatic monologues!

  • Create a new variable called wordCountMap that reduces the monologueLines to a map that resembles the output as shown above.

Resources

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

Contributors

annjohn avatar pletcher avatar thomastuts avatar dkennell avatar alpha-convert avatar

Watchers

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.