logo CodeStepByStep logo

minAndMax

Language/Type: JavaScript loops cumulative algorithms fencepost
Author: Melissa Hovik (on 2017/08/14)

Write a function named minAndMax that takes an array of numbers as a parameter and then prints its maximum and minimum values. Your function should throw an exception with the message, "array must contain at least one value" if passed a null or empty array. You may however assume the array contains only number types. If passed an array with only one element that number should be considered both the minimum and the maximum. Here is an example output when calling minAndMax([5, 12.5, -5, 2]):

Minimum Value = -5
Maximum Value = 12.5
Function: Write a JavaScript function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.