I have an exercise to create a function (lets call it "iterateAndSum") which will sum all numbers in array and return the result. I can't use reduce (which is easier). I have to focus on using while loop.
reduce
while
I tried and failed miserably:
function iterateAndSum(arr) { while (i--) { e += arr[i]; } }
function iterateAndSum(arr) { let i = 0; let e = 0; while (i < arr.length) { e += arr[i]; i++; } return e; }
2.1m questions
2.1m answers
60 comments
56.9k users