Question: code: javascript/rust /* TASK 2 (10pts): A good way to think about fold is that it _folds_ a list into a single value. This single

code: javascript/rust

/* TASK 2 (10pts):

A good way to think about fold is that it _folds_ a list into a single value.

This single value can, of course, also be anything -- even a list!

To emphasize this, your next task is to write an implementation of the map

function we saw in class using fold_left.

map takes in 2 arguments:

1. g - A function that is to be mapped over a list.

2. ls - The list that is to be mapped over.

Here's an example of how map is supposed to work:

map(x => x + 1, List([1, 2, 3])) ------> List([2,3,4])

map(x => x * 2, List([1, 2, 3])) ------> List([2,4,6])

You can normally do this using a loop construct, but your constraint here is

to define map using fold_left only.

Hint: the base value could be an empty list (List([])).

*/

const map = (g, ls) => /** **/ undefined; /** **/

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!