Question: /* 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

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!