185
rated 0 times
[
189]
[
4]
/ answers: 1 / hits: 39214
/ 12 Years ago, mon, november 26, 2012, 12:00:00
Let's assume I have a huge (1000+) list of objects like this:
[{name: 'john dow', age: 38, gender:'m'}, {name: 'jane dow', age: 18, gender:'f'}, ..]
I want to filter this list by name (character wise).
filter('j') => [{name: 'john dow', age: 38, gender:'m'}, {name: 'jane dow', age: 18, gender:'f'}, ..]
filter('jo') => [{name: 'john dow', age: 38, gender:'m'}, ..]
filter('dow') => [{name: 'john dow', age: 38, gender:'m'}, {name: 'jane dow', age: 18, gender:'f'}, ..]
What is the highest performance way to do that? RegEx is obviously one of the keys, ordering the list beforehand if you assume that user usually tend to start names from the beginning may also a good idea, but it only helps in some cases.
Are there any JavaScript built-in functions for mapping a filter? I'd expect those to be faster than JavaScript implementations.
P.S.: Yes I want to filter on client side because of offline capabilities I want to offer.
More From » performance