title: Check similarity of array values
body: <p>I got an array that with different values and I'd like to calculate a percentage value that symbolizes the similarity of all it's elements <strong>using maybe a threshold property</strong>.</p>
  
  <p>An array could look like this:</p>
  
  <pre><code>var array = [42.98, 42.89, 42.91, 42.98, 42.88] // should return nearly 100%
  
  var array = [42.98, 22.89, 42.91, 42.98, 42.88] // should return maybe 80%
  
  var array = [42.98, 332.89, 122.91, 5512.98, -12.88] // should return nearly 0%
  </code></pre>
  
  <hr>
  
  <p><strong>So 100% stands if all elements are the same
  ... and 0 % stands for the case the elements are way different. The adjustment is set by editing the threshold</strong></p>
  
  <p>I do not really know how to solve the problem (I'm an absolutely newbie)  - however this is all I got so far and obviously it is not working that way:</p>
  
  <pre><code>function checkSimilarity(array, threshold) {
      var sum = array.reduce((a, b) =&gt; a + b, 0),
          percentage = 0;
      for (var i =0; i&lt; array.length; i++) {
         var diff = (sum / array.length) * i
         percentage += diff
  
      }
      return percentage * (threshold/100)
  }
  </code></pre>
  
  <p>Any help how to solve my problem of creating a working algorithm would be very appreciated!</p>