title: JavaScript Codility Demo Solution
body: <p>I was looking at the demo Equi task on Codility last night and scored 12/100 for the following function:</p>
  
  <pre><code>function solution(A) {
      var n = A.length;
      var p = 0;
      var sum = 0;
      var sumLeft = 0;
      var sumRight = 0;
      var equilExists = 0;
  
      if (n == 0) {
          return -1;
      }
  
      for (i=0; i&lt;=n; i++) {
          sum = A[i];
          for (j=0; j&lt;=n; j++) {
          if (j &lt; i) {
              sumLeft += A[j];
          } else if (j &gt; i) {
              sumRight += A[j];
          }
          if (sumLeft == sumRight) {
              equilExists = 1;
              p = i;
              return p;
                  }
          }
      }
  
      if (equilExists == 0) {
          return -1;
      }
  }
  </code></pre>
  
  <p>For those of you not familiar with the task it can be found at <a href="http://blog.codility.com/2011/03/solutions-for-task-equi.html" rel="nofollow">http://blog.codility.com/2011/03/solutions-for-task-equi.html</a></p>
  
  <p>I was wondering if anyone could help point out where my solution falls down?</p>
  
  <p>Many thanks!</p>