Editing fast-array-filter This edit will create a new revision. Your details (optional) Name Email (won’t be displayed; might be used for Gravatar) URL Test case details Title * Published (uncheck if you want to fiddle around before making the page public) Description (in case you feel further explanation is needed)(Markdown syntax is allowed) This is an `Array#filter` implementation from a recent [140bytes code golf entry](https://gist.github.com/1031656#file_readme.md). It's faster than native `Array#filter` when iterating over large sparse arrays because it doesn't use the `length` property to calculate when it should stop iterating. Are you a spammer? (just answer the question) Preparation code Preparation code HTML (this will be inserted in the <body> of a valid HTML5 document in standards mode) (useful when testing DOM operations or including libraries) <script> Array.prototype.filter2 = function( a, //a function to test each value of the array against. Truthy values will be put into the new array and falsey values will be excluded from the new array b, // placeholder c, // placeholder d, // placeholder e // placeholder ) { c = this; // cache the array d = []; // array to hold the new values which match the expression for (e in c) // for each value in the array, ~~e + '' == e && e >= 0 && // coerce the array position and if valid, a.call(b, c[e], +e, c) && // pass the current value into the expression and if truthy, d.push(c[e]); // add it to the new array return d // give back the new array }; Array.prototype.filter3 = function( a, //a function to test each value of the array against. Truthy values will be put into the new array and falsey values will be excluded from the new array b, // placeholder c, // placeholder d, // placeholder e, // placeholder, i=0 ) { c = this; // cache the array d = []; // array to hold the new values which match the expression for (e in c) // for each value in the array, ~~e + '' == e && e >= 0 && // coerce the array position and if valid, a.call(b, c[e], +e, c) && // pass the current value into the expression and if truthy, d[i++] =c[e]; // add it to the new array return d // give back the new array }; </script> Include JavaScript libraries as follows: <script src="//cdn.ext/library.js"></script> Define setup for all tests (variables, functions, arrays or other objects that will be used in the tests) (runs before each clocked test loop, outside of the timed code region) (e.g. define local test variables, reset global variables, clear canvas, etc.) (see FAQ) var array = []; array[200] = 'a'; function callback(v) { return /\w+/.test(v); } Define teardown for all tests (runs after each clocked test loop, outside of the timed code region) (see FAQ) Code snippets to compare Test 1 Title Async (check if this is an asynchronous test) Code array.filter3(callback); Test 2 Title Async (check if this is an asynchronous test) Code array.filter2(callback);