Malj72
9/12/2017 - 11:57 AM

Average of numbers in array function

Determine an average of all the numbers in the array

function average(nmbrArray) {
  let sum = 0;  
      undef = 0;
  for (var i = 0; i < nmbrArray.length; i++) {
    if (nmbrArray[i] === undefined) {
      undef++;
      continue;
    }
    sum += nmbrArray[i]; 
  }  
  return sum / (i - undef);  
}