title: switchMaxMin-Java Script
body: <p>I have to write a function switchMaxMin(tab, n) that swaps the maximum element with the minimum element in an n-element array tab. We assume that all elements of the array are distinct (i. e. there are not a few maxima or minima). I don't know how to do this
  I started to write the code and I came up with this:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var tab = new Array(6, 4, 65, 34, 67, 89, 45, 7, 35, 79, 23, 56, 87, 12, 38, 9);
  var min = tab[0];
  var max = tab[0];
  document.write("Tablica: ");
  for (i = 1; i &lt; tab.length; i++) {
    document.write(tab[i] + ", ");
    if (min &gt; tab[i]) {
      min = tab[i];
    }
    if (max &lt; tab[i]) {
      max = tab[i];
    }
  }
  document.write("&lt;br /&gt;&lt;br /&gt;Max: " + max);
  document.write("&lt;br /&gt;Min: " + min);</code></pre>
  </div>
  </div>
  </p>