Created
December 18, 2013 15:47
javascript find in array with .reduce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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 }) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Loops over all elements, better use shim from es6-shim: https://github.com/paulmillr/es6-shim