title: Optimizing solution of Sum of Pairs: Codewars
body: <p>I want a help in optimising a solution of a problem, I already sort out the problem, but my code is not good enough for handling large array -
  <a href="https://www.codewars.com/kata/sum-of-pairs/" rel="nofollow noreferrer">codeWars : Sum of Pairs - problem </a> </p>
  
  <p>Here is my code -</p>
  
  <pre><code>var sum_pairs=function(e, sum){
  
  var result=null;
  var arrLen=e.length;
  for(let i=0;i&lt;arrLen-1;i++){
    let nextIndex=e.slice(i+1,arrLen).indexOf(sum-e[i]);
    if(nextIndex&gt;=0){ 
      result=[e[i],e[nextIndex+1+i]];
      arrLen=nextIndex+1+i; 
    }
  }
  return result;
  }
  </code></pre>
  
  <p>Well, I know this is not a good solution. Anyway, this passes all the test cases but failed when it encounter large array - 
  <a href="https://i.stack.imgur.com/8F2lq.png" rel="nofollow noreferrer">Result On codewars</a> </p>
  
  <p>I want to know how to optimise this code, and also Learn any technique to writing a good code.</p>