I have this code for a class where I\'m supposed to use the reduce() method to find the min and max values in an array. However, we are required to use only a single call to
The solution using Math.min() and Math.max() functions:
Math.min()
Math.max()
function minMax(items) { var minMaxArray = items.reduce(function (r, n) { r[0] = (!r[0])? n : Math.min(r[0], n); r[1] = (!r[1])? n : Math.max(r[1], n); return r; }, []); return minMaxArray; } console.log(minMax([4, 1, 2, 7, 6]));