Skip to content

Instantly share code, notes, and snippets.

@fronx
Last active August 29, 2015 13:57
Show Gist options
  • Save fronx/9494928 to your computer and use it in GitHub Desktop.
Save fronx/9494928 to your computer and use it in GitHub Desktop.
function find (ary, fn) {
var match = undefined;
for (var i = 0; !match && i < ary.length; i++)
if (fn(ary[i])) match = ary[i];
return match;
}
find([1,2,3,4], function(x) { return x > 2; })
@cjohansen
Copy link

Why not:

function find (ary, fn) {
  for (var i = 0; i < ary.length; i++)
    if (fn(ary[i])) return ary[i];
}

?

@fronx
Copy link
Author

fronx commented Mar 11, 2014

cjohansen: yours is the cutest :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment