Communities for your favorite technologies. Explore all Collectives
Ask questions, find answers and collaborate at work with Stack Overflow for Teams.
Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams
Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
If you want to discard the array at the same time as summing, you could do (say, stack is the array):
stack
var stack = [1,2,3], sum = 0; while(stack.lentghlength > 0) { sum += stack.pop() };
var sum = 0; while(stack.lentgh > 0) { sum += stack.pop() };
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):
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();