-5

Receives an integer array as argument •

  • The function transverses the array to determine the minimum and maximum values in the array

  • Displays the calculated information as illustrated below:

functionName([-8, -1, -87, -14, -81, -74, -20, -86, -61, -10]);

// would produce following message in console:

The minimum value in the array is: -87, the maximum value is -1
Gagan
  • 3
  • 1

2 Answers2

1

Math.min and Math.max return the minimum and maximum values. Since you want your function to print it out to the console, use console.log to print out these values, along with a templated string to have it in the format you want.

const minAndMax = (arr) => console.log(`The minimum value in the array is: ${Math.min(...arr)}, the maximum value is ${Math.max(...arr)}`)

minAndMax([-8, -1, -87, -14, -81, -74, -20, -86, -61, -10]);
Samathingamajig
  • 11,839
  • 3
  • 12
  • 34
0

this will work.

function yourFunc(arr){
 arr = arr.sort( (a,b) => a -b );
 console.info(`The minimum value in the array is: ${arr[0]}, the maximum value is ${arr[arr.length - 1]}`);
}
yourFunc([-8, -1, -87, -14, -81, -74, -20, -86, -61, -10])
Mritunjay
  • 27
  • 1
  • 7