twhite96
6/29/2017 - 1:58 AM

Finalized version of arrays section of The Web Developer Bootcamp

Finalized version of arrays section of The Web Developer Bootcamp

function printReverse(arr) {
  return arr.reverse();
}
printReverse([1,2,3,4]);

// Refactor to print on new line
function printReverse(arr){
  for(var i = arr.length - 1; i >= 0; i--) {
    console.log(arr[i]);
  }
}
printReverse([1,2,3,4]);

//** isUniform **//

function isUniform(array) {
  for(var i = 0; i < array.length -1; i++) {
    if(array[i] !== array[i + 1]) {
      return false;
    }
  }
  return true;
}

//** sumArray **//

function sumArray(arr) {
  var sum = 0;
  arr.forEach(function(element){
    sum += element;
  });
  return sum;
}

//** max **//

function max(arr) {
  var maxValue = 0;
  arr.forEach(function(element){
    if (maxValue < element) {
      maxValue = element;
    }
  });
  return maxValue;
}