Do this in Haskell. You MUST solve each problem using "map", "filter", "foldr", or "foldl". {- Implement the "min2" func

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Do this in Haskell. You MUST solve each problem using "map", "filter", "foldr", or "foldl". {- Implement the "min2" func

Post by answerhappygod »

Do this in Haskell.
You MUST solve each problem using "map", "filter", "foldr", or
"foldl".
{-
Implement the "min2" function.
min2: takes a list of numbers,
returns the second-smallest number of the
input list
Note that if a list contains DUPLICATES, the second-smallest
number and the smallest number may be identical;
your code should return it.
We also assume that all input lists contain at least TWO
numbers.
Examples:
min2 [2110, 4820,
3110, 4120] == 3110
min2 [2110, 4820,
2110, 4120] == 2110
-}
min2 :: Ord a => [a] -> a
-- YOUR CODE START HERE
-- YOUR CODE END HERE
{-
Test your implementation: all following expressions should
return "True"
min2 [2110, 4820, 3110, 4120] == 3110
min2 [2110, 4820, 2110, 4120] == 2110
min2 [1.2, 2.3, 1.2, 1.2] == 1.2
-}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply