On Fri, May 25, 2012 at 9:26 PM, Rich Walrath <[email protected]> wrote:
> Hello,
>
> I've been playing around with an iterative array method I wrote earlier
> today. I thought it would be a good idea to post it here and see wher
>
> The idea behind this method is to search for the best match. It does this by
> allowing you to specify a weighing function that calculates the best result
> based by comparing two of the values at a time.

This is pretty trivially done with reduce.  Just modify your function
very slightly:

arr.reduce(function(a,b) { return a.x > b.x ? a : b; });

Same efficiency as your iterative method.

~TJ
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to