title: Check if all array values are the same with reduce()
body: <p>I need to compare <strong>all values in ONE array</strong> to know if they're all equal or not.
  So this works fine and gives me the expected output</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 myArray1 = [50, 50, 50, 50, 50];  // all values are same, should return true
  var myArray2 = [50, 50, 50, 50, 51];  // last value differs, should return false
  
  function compare(array) {
      var isSame = true;
      for(var i=0; i &lt; array.length; i++) {
         isSame = array[0] === array[i] ? true : false;
      }
      return isSame;
  }
  
  console.log('compare 1:', compare(myArray1)); // true 
  console.log('compare 2:', compare(myArray2)); // false</code></pre>
  </div>
  </div>
  </p>
  
  <p>Then I've tried the same with <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce" rel="nofollow noreferrer">reduce()</a> but looks like I'm misunderstanding that function. They both say it is false. Am I doing something obviously wrong? Can I use <code>reduce()</code> to get what I need? If so how?</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 myArray1 = [50, 50, 50, 50, 50];
  var myArray2 = [50, 50, 50, 50, 51];
  
  console.log('reduce 1:', myArray1.reduce(
    function(a, b){
      return a === b ? true : false
    }
  ));
  
  console.log('reduce 2:', myArray2.reduce(
    function(a, b){
      return a === b ? true : false
    }
  ));</code></pre>
  </div>
  </div>
  </p>