Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
This is a patch that supports reduce function for jQuery.
$.reduce = function(arr, reduce_cb, prev) {
arr = arr.toArray();
if (Array.prototype.reduce) {
return, reduce_cb, prev);
$.each(arr, function(i, cur) {
result =, prev, cur, i, arr);
prev = cur;
return result;
$.fn.reduce = function (cb, prev) {
return $.reduce(this, function(prev, cur, i, arr) {
return, prev, cur, i, arr);
}, prev);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment