Skip to content

Instantly share code, notes, and snippets.

@radist2s
Forked from johnhunter/jQuery.reduce.js
Last active December 30, 2015 19:08
Show Gist options
  • Save radist2s/7871798 to your computer and use it in GitHub Desktop.
Save radist2s/7871798 to your computer and use it in GitHub Desktop.
/**
* 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