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 => /**
const ls_max = ls => /**
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 => /**
const ls_odds = ls => /**
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 => /**
const min_even = ls => /**
assert(max_even(ls) == 4);
assert(min_even(ls) == 2);
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started