Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

/* 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; /** **/

PLS HELP. I keep on getting wrong answers

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Analysis Using SQL And Excel

Authors: Gordon S Linoff

2nd Edition

111902143X, 9781119021438

More Books

Students also viewed these Databases questions

Question

Know the principles of effective service recovery systems.

Answered: 1 week ago

Question

Explain the service recovery paradox.

Answered: 1 week ago