File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -78,6 +78,43 @@ if (!Array.from) {
78
78
} ( ) ) ;
79
79
}
80
80
81
+ //reduce.js
82
+ /*
83
+ Source of the polyfill:
84
+ https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce#Polyfill
85
+
86
+ */
87
+
88
+ if ( ! Array . prototype . reduce ) {
89
+
90
+ Array . prototype . reduce = function ( callback ) {
91
+ 'use strict' ;
92
+ if ( this == null ) {
93
+ throw new TypeError ( 'Array.prototype.reduce called on null or undefined' ) ;
94
+ }
95
+ if ( typeof callback !== 'function' ) {
96
+ throw new TypeError ( callback + ' is not a function' ) ;
97
+ }
98
+ var t = Object ( this ) , len = t . length >>> 0 , k = 0 , value ;
99
+ if ( arguments . length == 2 ) {
100
+ value = arguments [ 1 ] ;
101
+ } else {
102
+ while ( k < len && ! ( k in t ) ) {
103
+ k ++ ;
104
+ }
105
+ if ( k >= len ) {
106
+ throw new TypeError ( 'Reduce of empty array with no initial value' ) ;
107
+ }
108
+ value = t [ k ++ ] ;
109
+ }
110
+ for ( ; k < len ; k ++ ) {
111
+ if ( k in t ) {
112
+ value = callback ( value , t [ k ] , k , t ) ;
113
+ }
114
+ }
115
+ return value ;
116
+ } ;
117
+ }
81
118
//assign.js
82
119
/**
83
120
* https://gist.github.com/WebReflection/10404826
You can’t perform that action at this time.
0 commit comments