Posts tagged “Method Signature”.

Javascript Array Filtering

In my last post, I presented a javascript function to convert a C# style lambda expression into a function as part of a library that provides functionality similar to Linq.

Today I’ll add a method for filtering. Linq has a where clause, so I’ll add a where method, callable through the Array prototype.

To specify the filter criteria, I’ll pass a function or lambda expression. I’ll also include support for passing extra parameters through to the filter function.

Our where method signature looks like this:

var where( filter, param,...);

where filter is a function or lambda string and param represents parameters passed through to the filter function.

Our filter function signature looks like this:

var filter( el, i, res, params,... );

where el is the value of the element from the array specified by index, i is the current index, res is the array of filtered elements, and params represents the extra parameters passed to the where call.

More… »