Last active
August 29, 2015 14:05
-
-
Save abruzzihraig/ffeea25203d6a86758b3 to your computer and use it in GitHub Desktop.
This is a patch that supports reduce function for jQuery.
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
$.reduce = function(arr, reduce_cb, prev) { | |
arr = arr.toArray(); | |
if (Array.prototype.reduce) { | |
return Array.prototype.reduce.call(arr, reduce_cb, prev); | |
} | |
$.each(arr, function(i, cur) { | |
result = reduce_cb.call(null, prev, cur, i, arr); | |
prev = cur; | |
}); | |
return result; | |
}; | |
$.fn.reduce = function (cb, prev) { | |
return $.reduce(this, function(prev, cur, i, arr) { | |
return cb.call(null, prev, cur, i, arr); | |
}, prev); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment