+1
-1
| { | ||
| "name": "rx-array", | ||
| "version": "0.0.2", | ||
| "version": "0.0.3", | ||
| "private": false, | ||
@@ -5,0 +5,0 @@ "description": "Adds map/reduce functions to JS Array prototype.", |
+4
-4
@@ -15,9 +15,9 @@ ### rx-array | ||
| No need to save the reference as the global Array object prototype now has the additional functions. The following functions are now available from any array | ||
| No need to save the reference as the global Array object prototype now has the additional functions. The following functions are now available from any array. Now it is not nice to shadow native implementations so I will not do that. | ||
| * map | ||
| * filter | ||
| * map (native) | ||
| * filter (native) | ||
| * mergeAll | ||
| * flatMap | ||
| * reduce | ||
| * reduce (native) | ||
| * zip | ||
@@ -24,0 +24,0 @@ |
+43
-43
@@ -19,10 +19,10 @@ // rx functions lovingly compiled from http://reactive-extensions.github.io/learnrx/ | ||
| // ``` | ||
| Array.prototype.map = function (projectionFunction) { | ||
| var results = []; | ||
| this.forEach(function (itemInArray) { | ||
| results.push(projectionFunction(itemInArray)); | ||
| }); | ||
| // Array.prototype.map = function (projectionFunction) { | ||
| // var results = []; | ||
| // this.forEach(function (itemInArray) { | ||
| // results.push(projectionFunction(itemInArray)); | ||
| // }); | ||
| return results; | ||
| }; | ||
| // return results; | ||
| // }; | ||
@@ -44,12 +44,12 @@ // filter | ||
| Array.prototype.filter = function (predicateFunction) { | ||
| var results = []; | ||
| this.forEach(function (itemInArray) { | ||
| if (predicateFunction(itemInArray)) { | ||
| results.push(itemInArray); | ||
| } | ||
| }); | ||
| // Array.prototype.filter = function (predicateFunction) { | ||
| // var results = []; | ||
| // this.forEach(function (itemInArray) { | ||
| // if (predicateFunction(itemInArray)) { | ||
| // results.push(itemInArray); | ||
| // } | ||
| // }); | ||
| return results; | ||
| }; | ||
| // return results; | ||
| // }; | ||
@@ -146,32 +146,32 @@ // mergeAll | ||
| Array.prototype.reduce = function (combiner, initialValue) { | ||
| var counter, | ||
| accumulatedValue; | ||
| // Array.prototype.reduce = function (combiner, initialValue) { | ||
| // var counter, | ||
| // accumulatedValue; | ||
| // If the array is empty, do nothing | ||
| if (this.length === 0) { | ||
| return this; | ||
| } else { | ||
| // If the user didn't pass an initial value, use the first item. | ||
| if (arguments.length === 1) { | ||
| counter = 1; | ||
| accumulatedValue = this[0]; | ||
| } else if (arguments.length >= 2) { | ||
| counter = 0; | ||
| accumulatedValue = initialValue; | ||
| } else { | ||
| throw new Error('Invalid arguments.'); | ||
| } | ||
| // // If the array is empty, do nothing | ||
| // if (this.length === 0) { | ||
| // return this; | ||
| // } else { | ||
| // // If the user didn't pass an initial value, use the first item. | ||
| // if (arguments.length === 1) { | ||
| // counter = 1; | ||
| // accumulatedValue = this[0]; | ||
| // } else if (arguments.length >= 2) { | ||
| // counter = 0; | ||
| // accumulatedValue = initialValue; | ||
| // } else { | ||
| // throw new Error('Invalid arguments.'); | ||
| // } | ||
| // Loop through the array, feeding the current value and the result of | ||
| // the previous computation back into the combiner function until | ||
| // we've exhausted the entire array and are left with only one function. | ||
| while (counter < this.length) { | ||
| accumulatedValue = combiner(accumulatedValue, this[counter]); | ||
| counter++; | ||
| } | ||
| // // Loop through the array, feeding the current value and the result of | ||
| // // the previous computation back into the combiner function until | ||
| // // we've exhausted the entire array and are left with only one function. | ||
| // while (counter < this.length) { | ||
| // accumulatedValue = combiner(accumulatedValue, this[counter]); | ||
| // counter++; | ||
| // } | ||
| return [accumulatedValue]; | ||
| } | ||
| }; | ||
| // return [accumulatedValue]; | ||
| // } | ||
| // }; | ||
@@ -178,0 +178,0 @@ // zip |
392119
0.06%