Skip to content

Instantly share code, notes, and snippets.

@herrernst
Created December 18, 2013 15:47
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