Javascript Array sumArrayItems()

Description

Javascript Array sumArrayItems()


Array.prototype.sumArrayItems = function() {
  var countIndex = this.length - 1;
  var sum =0;//from  ww  w . j  av a2  s  .  com
  while ( countIndex >= 0) {
    sum = sum + this[ countIndex ];
    countIndex--;
  }
  return sum;
}
var findMissing = function( arr1 , arr2 ) {
  return Math.abs( arr1 - arr2);
}
findMissing([1,2].sumArrayItems() , [1,2,5].sumArrayItems());



PreviousNext

Related