diff options
author | pabs@pablotron.org <pabs@pablotron.org> | 2014-12-18 02:07:08 -0500 |
---|---|---|
committer | pabs@pablotron.org <pabs@pablotron.org> | 2014-12-18 02:07:08 -0500 |
commit | d49ccd25b30efb777fcfc6007ee29785e8d843a2 (patch) | |
tree | d103e4097d11daa2660e8f80097eb03acb6d884f | |
parent | 44a1780688aa1bfec6928a19a41dc5b06742eede (diff) | |
download | luigi-template-d49ccd25b30efb777fcfc6007ee29785e8d843a2.tar.bz2 luigi-template-d49ccd25b30efb777fcfc6007ee29785e8d843a2.zip |
add array.reduce polyfill
-rw-r--r-- | luigi-template.js | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/luigi-template.js b/luigi-template.js index 806ddea..0afa0d6 100644 --- a/luigi-template.js +++ b/luigi-template.js @@ -109,6 +109,25 @@ LuigiTemplate = (function() { } })(); + // Array.reduce polyfill + var reduce = (function() { + if (Array.prototype.reduce) { + return function(a, fn, iv) { + return a.reduce(fn, iv); + }; + } else { + return function(a, fn, iv) { + var r = iv; + + each(a, function(v, i) { + r = fn(r, v, i, a); + }); + + return r; + }; + } + })(); + // String.scan polyfill function scan(s, re, fn) { var m; |