Étude 6-2: Iteration through Lists (More Practice)
Add two more functions to the stats
module:
maximum/1
, which is just
the same as minimum/1
, but don’t forget—as I did—to reverse the direction
of your test for “smaller” to become a test for “larger.” (This function
also already exists as lists:max/1
.)
range/1
, which takes a list of numbers as its argument and returns a
list of two numbers: the minimum and maximum entries in the list.
1>
c
(
stats
).
{ok,stats}
2>
N
=
[
4
,
1
,
7
,
-
17
,
8
,
2
,
5
].
[4,1,7,-17,8,2,5]
3>
stats
:
maximum
(
N
).
8
4>
stats
:
range
(
N
).
[-17,8]
Get Études for Erlang now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.