Skip to content

Instantly share code, notes, and snippets.

@rmcvey
Last active August 29, 2015 14:19
Show Gist options
  • Save rmcvey/20bc67e149f435fbe067 to your computer and use it in GitHub Desktop.
Save rmcvey/20bc67e149f435fbe067 to your computer and use it in GitHub Desktop.
Array reduce jQuery objects
/**
* jQuery Reduce
* Function signature is identical to native Array.reduce - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce
* @author Rob McVey
*/
$.fn.reduce = function(){
var args = Array.prototype.slice.call(arguments, 0);
return Array.prototype.slice.call(this, 0).reduce.apply(this, args);
}
/**
* var total = $('.someSelector').reduce(function(prev){
* return prev + parseInt($(this).find('.numValue').text());
* }, 0);
* /
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment