Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/* QUESTION 2: Min/Max and Evens/Odds */ /* Implement min and max functions using fold_left An empty list has no minimum or maximum value, therefore,

/* QUESTION 2: Min/Max and Evens/Odds */

/*

Implement min and max functions using fold_left

An empty list has no minimum or maximum value, therefore, return undefined.

*/

const ls_min = ls => /** **/ undefined; /** **/

const ls_max = ls => /** **/ undefined; /** **/

assert(ls_min(ls) == 1);

assert(ls_max(ls) == 5);

/*

Implement two functions that return evens and odds from a list of integers

using filter

*/

const ls_evens = ls => /** **/ undefined; /** **/

const ls_odds = ls => /** **/ undefined; /** **/

assert(ls_evens(ls).equals(List([2,4])));

assert(ls_odds(ls).equals(List([1,3,5])));

/*

Using function composition, implement a function that returns the maximum

number in the even subset of a given list and another function that returns

the minimum number in the evens. Recall the definition of compose below:

*/

function compose(f, g) {

return (x) => {

return f(g(x));

};

}

const max_even = ls => /** **/ undefined; /** **/

const min_even = ls => /** **/ undefined; /** **/

assert(max_even(ls) == 4);

assert(min_even(ls) == 2);

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

The Manga Guide To Databases

Authors: Mana Takahashi, Shoko Azuma, Co Ltd Trend

1st Edition

1593271905, 978-1593271909

More Books

Students also viewed these Databases questions