Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN SCALA Problem 1: map, filter, reduce on containers (40 points) Solve the problems using a combination of map, filter and foldLeft/foldRight opertions over lists.

IN SCALAimage text in transcribed

Problem 1: map, filter, reduce on containers (40 points) Solve the problems using a combination of map, filter and foldLeft/foldRight opertions over lists. The use of mutables, recursion, For/While loops is forbidden for all problems. Each problem has very specific set of allowed LIST API functions. Those are the only functions you can use. Other API functions are not allowed. There are no restrictions on use of integer operations (addition, subtraction, division, mod etc..) or use of if-then-else, case-pattern matching and other scala constructs (however once again no loops of any kind and no use of var). There are no restrictions on the use of named "helper" function vs anonymous functions. Avoid the use of return in your anonymous function -- it may cause errors that are hard to debug. A: Compute a list of element-wise maximum of two lists of numbers (5 points). Write a function elementWiseMax that takes two lists 1stA and lsts of integers. The lists are given to be the same size. You need to compare the lists element-wise, i.e., compare ith element of 1stA to ith element of lsts, and return a new list containing the maximum of compared elements at each index. elementWiseMax([20, 21, ..., an], [bo, b1, ...,bn]) = [max(ao, bo), max(21,b),..., max(an, bn)] Maximum of two integers is defined as following: max(a, b) = if b; > a; then b; else a; Example elementWiseMax(List(1,3,5,4), List(-1,5,-2,7)) should return List(1,5,5,7). Restrictions List API functions that you are allowed to use: zip and map. Use of any other List API function is not allowed. You are not allowed to use var, any kind of loops or recursion. You can look the list API documentation for scala to find out more about these functions. Post/Search on piazza if you are unsure. n [2] : 1 def elementWiseMax(1stA: List[Int], IstB: List[Int]): List[Int] = { require(1stA.length == lsts.length) // YOUR CODE HERE } 8

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

Database Systems Design Implementation And Management

Authors: Peter Rob, Carlos Coronel

6th International Edition

061921323X, 978-0619213237

More Books

Students also viewed these Databases questions

Question

=+2 Why did OBI create Centers of Excellence?

Answered: 1 week ago