Advertisement
Guest User

Untitled

a guest
Apr 26th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.27 KB | None | 0 0
  1. /*do not understand why i = 1 instead of 0 as this means the loop begins iterating on the second item in the array*/
  2.  
  3. function average(numbers) {
  4. let total = numbers[0];
  5. for (let i = 1; i < numbers.length; i++) {
  6. total += numbers[i];
  7. }
  8. return total / numbers.length;
  9. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement