Javascript Array SumArray(arr)

Description

Javascript Array SumArray(arr)



Array.prototype.SumArray = function(arr) {
    var sum = [];
    if (arr != null && this.length == arr.length) {
        for (let i = 0; i < this.length; i++) {
            sum.push(this[i] + arr[i]);//  www .  java2 s  .  c o  m
        }
    }
    return sum;
}

//test
var x = [1,2,3,4];
var y = [5,6,7,8];
var z = x.SumArray(y);
console.log(z);



PreviousNext

Related