From d49ccd25b30efb777fcfc6007ee29785e8d843a2 Mon Sep 17 00:00:00 2001 From: "pabs@pablotron.org" Date: Thu, 18 Dec 2014 02:07:08 -0500 Subject: add array.reduce polyfill --- luigi-template.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'luigi-template.js') 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; -- cgit v1.2.3