How would you return the maximum and minimum of an array in a function?

Hello, everyone. I’m trying to figure out how to return Math.min() and Math.max() inside a function. Currently, the question is asking me to return both so that the minimum and maximum of an array display at the same time (i.e [ 2, 3 , 5] //=> [2, 5]). however I think I may be messing up because it’s only returning the minimum. Thanks!

function minMax(arr) {
	var min = Math.min(...arr);
	var max = Math.max(...arr);
			return min, max;
                // only gives me [3], need [3, 5]

}minMax([3, 4, 5])

You can only return one item from a function. If you have two things to return, you have to put them in an array or an object, or something like that.

2 Likes

You need to return inside of an array or an object if you want to return multiple things.

1 Like

Return inside of an array, Thanks everyone!

1 Like