jasonformat.com icon indicating copy to clipboard operation
jasonformat.com copied to clipboard

I have no Twitter but I'd like to comment:

Open tomgp opened this issue 4 years ago • 1 comments

Hi Jason,

Apologies for (mis)using github issues as a place for comments (see subject line)

I just read your blogpost: Quick tip: reusable Array search predicates. In the past I've achieved a similar effect (in terms of developer experience) by having a function that returns a function eg.

const byId = (value) => {
  return (element) => {
    element.id == value;
  }
}

myArray.filter( byId(12) );

Of course each time I'm creating a new function for the predicate so I'm not really reusing it but it feels that way (as I say, dev experience...). I wonder if you have any insight into how the two approaches might differ, performance or other-wise.

Thanks for writing your blog, it's always interesting.

Tom

tomgp avatar Jun 18 '21 12:06 tomgp

Hiya! I actually added this (higher order fn) to the benchmark in the post - it's faster and generally I'd recommend an approach like that since it's much more clear what is going on.

developit avatar Jun 19 '21 17:06 developit