AS3 Array filter function with multiple parameters
Recently I have been working on a pure AS3 project that at one point required me to do quite a lot of filtering on a few arrays.
While AS3 provides a nice new set of functions for filtering, they all had a common shortcoming for my usage scenario, they can not accept parameters directly.
Let’s say that I need to filter an array acording to value range, not a problem with filter function:
Now what to do if I need to have more ranges, for example, people in thirties and fourties, this quickly becomes unruly mess of single use functions and a whole lot of copy/paste error prone code.
Fortunately there is a better way. If you pass an object to the filter function, the function will execute in the scope of that object, and you will be able to access it’s parameters.