title: Sum of 2 elements in array - Algorithm - JavaScript
body: <p>I'm working on JavaScript algorithms and could use some help. What am I doing wrong exactly?</p>
  <p>// Given an array of arr, positive integers, and another number X.</p>
  <p>// Determine whether or not there exist two elements in arr whose sum is exactly X.</p>
  <pre><code>function keyPair(arr, x){
      var sum=false;
      var key=0;
      var temp=0;
      for(var i=0;i&lt;=arr.length;i++){
          while(sum=false){
              key=arr[i];
              arr[i]=temp;
              temp=key;
          }
          if(temp+arr[i]==x){
              sum=true;
          }
      }
      console.log(sum);
  }
  keyPair([1,2,4,3,6], 4);
  </code></pre>