Remove without copy (v5)

Revision 5 of this benchmark created on


Setup

var a = [0,1,2,3,4,5,6,7,8,9];
    var i = 0
    while(i<100000){
    a.push(i)
    i++;
    }
    a.splice( 1, 0, 2 );
    a.push( 2 );
    a.push( 2 );

Test runner

Ready to run.

Testing in
TestOps/sec
Felipe
function removeWithoutCopy(arr, item) {
    var i = 0,
      l = arr.length;
    for (i = 0; i < l; i++) {
      if(arr[i] == item){
        arr.splice(i, 1);
        --i;
        --l;
      }
    }
    return arr;
  };

removeWithoutCopy(a, 2)
ready
Allan
function removeWithoutCopy(arr, item) {
var i;
    while (i = arr.indexOf(item) && i > -1) {
        arr.splice(i, 1);
    }
    return arr;
  };

removeWithoutCopy(a, 2)
ready
Felipe Allan Huggle
function removeWithoutCopy(arr, item) {
 var l = arr.length;

    while (l > 0) {
      
      if(arr[l] == item){
        arr.splice(l, 1);
        //--l;
      }
      --l;
    }
    return arr;
};

removeWithoutCopy(a, 2)
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.