title: Given an array of integers, how do I find the sum of its elements with some simple constraints in JavaScript?
body: <p>To find the sum of array's elements
  I have tried this approach however the output comes undefined instead of an integer</p>
  <p>constraints are <code>array.length &gt; 0</code> &amp;&amp; <code>array[i] &lt;= 1000</code></p>
  <pre class="lang-html prettyprint-override"><code>function simpleArraySum(ar) {
      let acc = 0;
      for (let i = 0; ar.length; i++) {
          if (ar.length &gt; 0 &amp;&amp; ar[i] &lt;= 1000) {
              acc += ar[i]
          } else {
              return
          }
      }
      return acc;
  }
  </code></pre>
  <p>Any help would be appreciated.</p>