Skip to content

Instantly share code, notes, and snippets.

@herrernst
Created December 18, 2013 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save herrernst/8024580 to your computer and use it in GitHub Desktop.
Save herrernst/8024580 to your computer and use it in GitHub Desktop.
javascript find in array with .reduce
//quick and dirty, does not consider all function params and this yet
Array.prototype.find = function (predicate) {
return this.reduce(function(prev, cur){return predicate(cur) ? cur : prev })
}
@herrernst
Copy link
Author

Loops over all elements, better use shim from es6-shim: https://github.com/paulmillr/es6-shim

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