We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 177b4c3 + 8053619 commit 8ca9d8dCopy full SHA for 8ca9d8d
Array/reduce.js
@@ -0,0 +1,27 @@
1
+Array.prototype.reduce = function(callback) {
2
+ 'use strict';
3
+ if (this == null) {
4
+ throw new TypeError('Array.prototype.reduce called on null or undefined');
5
+ }
6
+ if (typeof callback !== 'function') {
7
+ throw new TypeError(callback + ' is not a function');
8
9
+ var t = Object(this), len = t.length >>> 0, k = 0, value;
10
+ if (arguments.length == 2) {
11
+ value = arguments[1];
12
+ } else {
13
+ while (k < len && !(k in t)) {
14
+ k++;
15
16
+ if (k >= len) {
17
+ throw new TypeError('Reduce of empty array with no initial value');
18
19
+ value = t[k++];
20
21
+ for (; k < len; k++) {
22
+ if (k in t) {
23
+ value = callback(value, t[k], k, t);
24
25
26
+ return value;
27
+};
0 commit comments