Skip to main content
fixed a typo, then expanded the code example slightly.
Source Link

If you want to discard the array at the same time as summing, you could do (say, stack is the array):

var stack = [1,2,3],
    sum = 0;
while(stack.lentghlength > 0) { sum += stack.pop() };

If you want to discard the array at the same time as summing, you could do (say, stack is the array):

var sum = 0;
while(stack.lentgh > 0) { sum += stack.pop() };

If you want to discard the array at the same time as summing, you could do (say, stack is the array):

var stack = [1,2,3],
    sum = 0;
while(stack.length > 0) { sum += stack.pop() };

If you want to discard the array at the same time as summing, you could do (say, 'stack'stack is the array):

        var sum = 0;
        while(stack.lentgh > 0) { sum += stack.pop() };

If you want to discard the array at the same time as summing, you could do (say, 'stack' is the array):

        var sum = 0;
        while(stack.lentgh > 0) sum += stack.pop();

If you want to discard the array at the same time as summing, you could do (say, stack is the array):

var sum = 0;
while(stack.lentgh > 0) { sum += stack.pop() };
Source Link
btk
  • 3.2k
  • 2
  • 31
  • 30

If you want to discard the array at the same time as summing, you could do (say, 'stack' is the array):

        var sum = 0;
        while(stack.lentgh > 0) sum += stack.pop();