Last active
August 29, 2015 14:19
-
-
Save rmcvey/20bc67e149f435fbe067 to your computer and use it in GitHub Desktop.
Array reduce jQuery objects
This file contains hidden or 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 | |
* 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