-
-
Save radist2s/7871798 to your computer and use it in GitHub Desktop.
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
/** | |
* jQuery.reduce - a jQuery plugin for functional programming | |
* @author Alex Batalov, John Hunter | |
* use: $('.elements').reduce(function(memo){return memo + $(this).height()}, 0); | |
* fnReduce is called with arguments: [valueInitial, value, i, arr] | |
* | |
* created 2010-09-17 | |
* modiffied 2013-12-09 | |
*/ | |
jQuery.fn.reduce = function(fnReduce, valueInitial) { | |
valueInitial = valueInitial !== undefined ? valueInitial : 0 | |
jQuery(this).each(function() { | |
valueInitial = fnReduce.call(this, valueInitial); | |
}); | |
return valueInitial; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment