I think I found a bug

Tell us what’s happening:

Your code so far


function dropElements(arr, func) {
  var length = arr.length;
  var continua = 1;
  for (var i = 0; i < times; i++) {
    if (func(arr[0])) {
      continua = 0;
    }
    else {
      arr.shift()
    }
  }
  return arr
}

dropElements([1, 2, 3], function(n) {return n < 3; });

Why when I don’t assign length to arr.length and loop through the array like this:
for ( var i = 0; i < arr.length; i++) {
}
it does not pass one of the tests? Isn’t that a bug?

arr.length is changed in the loops, so you can’t use it as a way to loop through all the array. You need to store that length somewhere before the array is changed

Try console.log(arr.length) inside the loop and see

1 Like