My good colleague Paddington bear has just asked me for some help with a marvellous mobile project he has devised. He has some locally stored JSON arrays that he needs to filter based on various fields throughout the code and he was looking for a nice way to reduce the complexity without having to do nasty loops everywhere and in different ways.
I came up with this example that we then turned into something for him (that you aren't allowed to see :-/) but I thought it might be of value to someone else.
Basically, the code takes the onus of doing the filtering out of the filter function so you then pass the array and the function upon which it is filtered at the same time.
Take a peek, I am sure there's some nicer ways of doing things but I just coded it as we were talking and now I am posting it. He has refined the production version and you guys can do the same if you like the idea!