title: Given an array of integers, find the two elements that sum closest to 0.
body: <p>I'm solving this problem where</p>
  
  <p><strong>Problem:</strong></p>
  
  <blockquote>
    <p>Given an array of integers, find the two elements that sum closest to
    0.</p>
  </blockquote>
  
  <p>My NativeJS solution:</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 a = [1,3,4,-1,-2,4,5,-9];
  
  function sumZero(arr){
    var temp=null;
    var result=null;
    arr.forEach(function(val, i){
      if(i===0){
        temp = (a[i]+a[i+1]);
        result = i;
      } else if(temp &gt; a[i] + a[i+1]){
        temp = (a[i]+a[i+1]);
        result = i;
      }
    });
    return result;
  }
  
  sumZero(a); // index 6 and 7 (result, result+1)
  
  //Implementation using reduce
  function sumZero2(arr){
    arr.reduce(function(temp, val, i){
      //console.log(i);
      if(temp &gt; a[i]+a[i+1])
        return i;
    }, 0);
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>I'm getting the correct results using native implementation but I couldn't solve the problem using reduce.</p>
  
  <p>Can someone help me withe my logic?</p>