Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a file called index.htmi. Inside this file create a javascript function c

ID: 3594145 • Letter: C

Question

Create a file called index.htmi. Inside this file create a javascript function called findMinMax. This function should take an array of numbers and return an array with two numbers wnich are the min and max values of the array that was passed in. Log the returned value to the console.Do NOT use the array sort method or any pre-written min and max javascript functions. You also do not need to write your own sort method to solve this problem unless you want too It can be solved without sorting the array Example console log(findMinMaxi1,4,-5,-4,30,2|), result should be [-5, 30]

Explanation / Answer

<!DOCTYPE html>

<html>

<head>

<script>

var i,min,max;

function findMinMax(nums){

min = nums[0];

max = nums[0];

for(i=1;i<nums.length;i++){

if(min>nums[i]){min=nums[i];}

if(max<nums[i]){max=nums[i];}

}

var arr = [min,max];

return arr;

}

console.log(findMinMax([1,4,-5,-4,30,2]));

</script>

</head>

<body>

</body>

</html>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote