Map Reduce & Jest Lab

In this lab, you will get practice with the Map Reduce design paradigm in javascript.

The Lodash library is a popular javascript library that implements several useful functions.  One of these functions in called chunk. The chunk function takes two parameters, the array, and the size of the chunk.

Instead of using the javascript library your task is to implement the chunk function.

You will first implement the chuck function using the map function and then using the reduce function. If the array can’t be chunk evening add the remaining items to the last array.  (See the second example)

Implement the chunk function using only the Map function

Implement the chunk function using only the Map function.


_.chunk(['a', 'b', 'c', 'd'], 2);
// => [['a', 'b'], ['c', 'd']]

Run the Jest test cases. If the test cases pass.
Upload your code to collab and answer the quiz question.

Implement the chunk function using only the Reduce function

Open the file called reduceMap.js in the lab folder.  Implement the chunk function using only the Reduce Function.


_.chunk(['a', 'b', 'c', 'd'], 3);
// => [['a', 'b', 'c'], ['d']]

Run the Jest test cases. If the test cases pass.
Upload your code to collab and answer the quiz question.

Use the template below.

Download and edit the following template. Lab4-Chunk Upload your code once to assignment session on collab when you are done.

Summitting.

Then download the 10000 array file and generate a chunked array using the number specified in the quiz. Upload the result to collab under the appropriate lab number 4.  

Also

%d bloggers like this: