title: Using reduce() to find min and max values?
body: <p>I have this code for a class where I'm supposed to use the <code>reduce()</code> method to find the min and max values in an array. However, we are required to use only a single call to reduce. The return array should be of size 2, but I know that the <code>reduce()</code> method always returns an array of size 1.</p>
  <p>I'm able to obtain the minimum value using the code below, however I don't know how to obtain the max value in that same call. I assume that once I do obtain the max value that I just push it to the array after the <code>reduce()</code> method finishes.</p>
  <pre class="lang-js prettyprint-override"><code>/**
   * Takes an array of numbers and returns an array of size 2,
   * where the first element is the smallest element in items,
   * and the second element is the largest element in items.
   *
   * Must do this by using a single call to reduce.
   *
   * For example, minMax([4, 1, 2, 7, 6]) returns [1, 7]
   */
  function minMax(items) {
    var minMaxArray = items.reduce(
      (accumulator, currentValue) =&gt; {
        return (accumulator &lt; currentValue ? accumulator : currentValue);
      }
    );
  
    return minMaxArray;
  }
  </code></pre>