title: Mutating the array gives NULL as the first entry
body: <p><strong>QUESTION</strong><br />
  Given an integer n and an array a of length n, your task is to apply the following mutation to a:</p>
  <p>Array a mutates into a new array b of length n.
  For each i from 0 to n - 1, b[i] = a[i - 1] + a[i] + a[i + 1].
  If some element in the sum a[i - 1] + a[i] + a[i + 1] does not exist, it should be set to 0. For example, b[0] should be equal to 0 + a[0] + a<a href="https://i.stack.imgur.com/mi8FH.png" rel="nofollow noreferrer">1</a>.</p>
  <p><strong>CODE</strong></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>function mutateTheArray(n, a) {
      let b = []
  
      for(i=0; i &lt;= n-1; i++){
          if(i==0){
              b[0] = a[0] + a[1]
          }
          if(i == n-1){
              b[i] = a[i-1] + a[i]
          }
          else{
              b[i] = a[i-1] + a[i] + a[i+1]
          }
      }
      return b
  }
  console.log(mutateTheArray(5, [4, 0, 1, -2, 3]));</code></pre>
  </div>
  </div>
  </p>
  <p><strong>RESULT</strong>
  <a href="https://i.stack.imgur.com/mi8FH.png" rel="nofollow noreferrer">enter image description here</a></p>
  <p>Why is the first entry NULL?</p>