mardi 20 octobre 2020

array exercise without using any

Calculate the sum of array of numbers 1should create a function named sumNumbers 2should return zero if receives an empty array when called 3should return the sum with one number array 4should return zero if all elements are zero 5should return the sum when passed array of numbers

CODE:

const numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10];

function sumNumbers(arrNum){
  let sum = 0 ;
  if(arrNum.length === 0){
     return 0;
  }//elseif(arrNum[0] !== NaN ){
  //NO CLUE
  
  for( let i = 0; i < arrNum.length; i++){
  sum += arrNum[i];
  }
  return sum;
}

sumNumbers(numbers)



I dont't really know how to fix .3 and .4

Aucun commentaire:

Enregistrer un commentaire