title: How to compare every number in an array against each other? (javascript)
body: <p>I have a set of numbers which are displayed like followed;</p>
  
  <p><code>var data = "615:415,600:400,600:400,300:300"</code></p>
  
  <p>Each number represents an x/y coordinate, and I would like to add a value next to each one which is calculated based on the frequency of the number within a range.</p>
  
  <p>So, I would like to be able to compare each value against all others in this string, and from this perform the following functions;</p>
  
  <ol>
  <li>Remove the number from the string if it is a duplicate, and add :1</li>
  <li><strong>If the x/y numbers are both within a range of 15 against any other number, add:1</strong></li>
  <li>If there are no matches, add :0</li>
  <li>Turn into array</li>
  </ol>
  
  <p>So using the data string, it would be transformed to;</p>
  
  <p><code>var data = "615:415:1, 600:400:2, 300:300:0"</code></p>
  
  <p>I have been trying to do this using a reducer function, but I'm struggling with mainly step 2. I'm hoping someone can help out?</p>
  
  <p>Thanks - Code + Plunk below!</p>
  
  <hr>
  
  <p><a href="http://plnkr.co/edit/zPW1844cLnUFAlEI77jq?p=preview" rel="nofollow noreferrer">http://plnkr.co/edit/zPW1844cLnUFAlEI77jq?p=preview</a></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 result = [];
  var data = "615:415,600:400,600:400,300:300"
  var count = 0;
  
  var reducer = function(p, c, i, a) {
  
    if (p &amp;&amp; p !== c) {
  
      var _t = p.split(":");
      result.push({
        x: _t[0],
        y: _t[1],
        value: count
      });
  
      count = 0;
      if (i === a.length - 1) {
        _t = c.split(":");
        result.push({
          x: _t[0],
          y: _t[1],
          value: count
        });
      }
    }
    else {
      count++;
    }
    return c
  }
  
  data.split(',').sort().reduce(reducer);
  
  console.log(result)</code></pre>
  </div>
  </div>
  </p>