Javascript - Is passing array[0] directly vs array[0] by i= 0 array[i] fundementally different inside an "if" statement?
<p>Working on a programming challenge. The objective is to create a function that "Drop[s] the elements of an array (first argument), starting from the front, until the predicate (second argument) returns true."</p>

<pre><code>dropElements([1, 2, 3, 4], function(n) {return n &gt; 5;});

function dropElements(arr, func) {
    for (i = 0; i &lt; arr.length-1; i++) {
        if(func(arr[i])) {
            break;
        }
        else { 
            arr.splice(i,1);
            i--;
        }
    }
    return arr; 
}
</code></pre>

<p>returns <code>[4]</code> which is the incorrect answer</p>

<p>However the following:</p>

<pre><code>dropElements([1, 2, 3, 4], function(n) {return n &gt; 5;});

function dropElements(arr, func) {
    for (i = 0; i &lt; arr.length; i++) {
        if (func(arr[0])) {
            break;
        } 
        else {
            arr.shift();
            i--;
        }
    }
    return arr; 
}
</code></pre>

<p>returns <code>[]</code> which is the correct answer</p>

<p>I wrote it all out by hand and it looks like it should out put the same. Is it something to do with coercion that I don't understand? </p>