I tried two different way to do something and I am surprised by the performance result :
I have 2 versions of a function :
Using a for
:
Consider these two examples:
for (var i = 0; i < array.length; i++) {
doThing(array[i]);
}
vs.
function processItem(item) {
doThing(item);
}
for (var i = 0; i < array.length; i++) {
processItem(array[i]);
}
This is basically the difference between the two. There also has to be some logic inside of filter
and some
for handling the return value from processItem
but basically you're stacking a whole extra function call on top of your loop.