Git Product home page Git Product logo

javascript-map-reduce-lab's Introduction

JavaScript Map-Reduce Lab

Overview

In this lab, you'll practice using reduce() and map() both separately and together on real data.

Introduction

This is it, the final challenge! Now that we're confident in our ability to use .map() and .reduce(), these challenges should prove sufficiently easy!

In this lab, we're going to work with GitHub API data — more specifically, issues related to courses on Learn.co. We'll analyze this data using .map() and .reduce(), providing us with (some not so) valuable insights!

Updating the API

Let's say GitHub has updated their API URL. That means we're using old data! Let's bring our data up-to-date.

  • Create a variable called issuesWithUpdatedApiUrl
  • The value of this variable is the mapped issues array, replacing any mention of 'api.github.com' (in issue.url) with 'api-v2.github.com'
  • Make sure you don't modify the original objects in the issues array

Counting the comments

To get a quick overview of our community's activity, let's sum up all comments of every issue.

  • The result should be in a variable called commentCountAcrossIssues
  • First, map the issues array and pull out the comments_count, to make things easier
  • Next, reduce the array of comment counts and add them all together
  • Feel free to chain these operations on the issues array for brevity — no need for a temporary variable!

Filtering for open issues

Looking at the data, it seems like some issues are closed already. Those aren't really relevant, so let's create a new array that only has open issues.

  • The result should be in a variable called openIssues
  • This new array should only contain issues where issue.state is set to 'open'

I'm not a robot

Some issues have been automatically created by the Learn.co bot. Let's filter these out, so we only see issues created by actual humans.

  • The result should be in a variable called nonAutomaticIssues
  • This new array should only contain issues that are not automatically created
  • Hint: check the issue.body for a clue

Showing off

Now that we have our nonAutomaticIssues, let's print these out in a table in our HTML page. The base markup has been provided for you in index.html — all we need to do is add rows to the table body.

  • Use the DOM API to set the HTML of the table body to a list of table rows that have three columns: the issue body, the date and the state of the issue (open or closed)
  • To easily create your HTML markup for all the rows, use .map()
  • Hint: the innerHTML property expects a string, so don't forget to turn your array into one big string by using .join()

Resources

javascript-map-reduce-lab's People

Contributors

annjohn avatar bhollan avatar pletcher avatar thomastuts avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

bhollan

javascript-map-reduce-lab's Issues

Limited time provided for final test

The final test, "Showing Off", requires a DOM interaction that involves a lot of data.

Even by first setting the whole content first, as a string and then setting it as the innerHTML of the '#results' node, I end up losing 3 seconds on this test alone. Would it be adequate to set a different time limit for this test?

Better Instructions

This isn't so much an issue with anything breaking as it is to help people understand how you are looking for solutions.

It's not mentioned in the previous lessons that you can pass in different data types when using the aggregate array functions. I feel like mentioning you can pass in an empty array or empty object, and that what you return is based on things like this will help people understand the logic of what's actually happening in these exercises.

It could be just me though...but I still believe talking about this would help!

Possible Wrong value for commentCountAcrossIssues

In the tests commentCountAcrossIssues is expected to have a value of 703.
But several attempts to count the values yield a total of 702 comments.

I Have tried the following

var commentCountAcrossIssues = issues.map(
  issue => issue.comments_count ? issue.comments_count : 0
).reduce(
  (total, currentCount) => total + currentCount
);

and this

var commentCountAcrossIssues = issues.map(
  issue => issue.comments_count 
).reduce(
  (total, currentCount) => total + (isNaN(currentCount) ? 0 : currentCount)
);

In both the cases the commentCountAcrossIssues equals to 702.
Please do correct me if I'm wrong.

@aviflombaum

Missing Module

[19:28:01] javascript-map-reduce-lab-g-416 (master)
// ♥ learn

[email protected] test /mnt/f/Code/GitHub/react intro/javascript-map-reduce-lab-g-416
mocha -R mocha-multi --reporter-options nyan=-,json=.results.json

0 -,------,
1 -
| /_/
0 -~|( x .x)
-_ "" ""

0 passing (22ms)
1 failing

  1. "before all" hook:
    Cannot find module 'jsdom/lib/old-api'
    Require stack:
  • /mnt/f/Code/GitHub/react intro/javascript-map-reduce-lab-g-416/node_modules/mocha-jsdom/index.js
  • /mnt/f/Code/GitHub/react intro/javascript-map-reduce-lab-g-416/test/root.js
  • /mnt/f/Code/GitHub/react intro/javascript-map-reduce-lab-g-416/node_modules/mocha/lib/mocha.js
  • /mnt/f/Code/GitHub/react intro/javascript-map-reduce-lab-g-416/node_modules/mocha/index.js
  • /mnt/f/Code/GitHub/react intro/javascript-map-reduce-lab-g-416/node_modules/mocha/bin/_mocha
    Error: Cannot find module 'jsdom/lib/old-api'
    Require stack:
    • /mnt/f/Code/GitHub/react intro/javascript-map-reduce-lab-g-416/node_modules/mocha-jsdom/index.js
    • /mnt/f/Code/GitHub/react intro/javascript-map-reduce-lab-g-416/test/root.js
      at Function.Module._resolveFilename (internal/modules/cjs/loader.js:982:15)
      at Function.Module._load (internal/modules/cjs/loader.js:864:27)
      at Module.require (internal/modules/cjs/loader.js:1044:19)
      at require (internal/modules/cjs/helpers.js:77:18)
      at Context. (node_modules/mocha-jsdom/index.js:53:5)
      at processImmediate (internal/timers.js:456:21)

npm ERR! Test failed. See above for more details.

OpenIssues only checks that none are closed...

And appears to accept a return value of nothing as passing the test (or any value so long as "closed" isn't present).

Final test also appears not to check whether or not data is displayed properly.. I had forgotten to interpolate so "issue.body" was showing up as literal text and the test still passed.

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.