Consider the following arrays:
// The goal is to calculate these arrays against each other.
var a = [1,2,3]
var b = [1,2,3]
var c = [3,4,5]
// ->
var result = [5, 8, 11]
While there are methods available to calculate two arrays at a time, how can we sum n arrays together?
Array.prototype.Sum = function (arr) {
var s = [];
if (arr != null && this.length == arr.length) {
for (var i = 0; i < arr.length; i++) {
var c = this[i] + arr[i]
s.push(c);
}
}
return s;
}