function getSumFn(){
var prevSum = 0;
return function sum(value){
prevSum = prevSum + value;
return prevSum;
}
}
const sum = getSumFn();
console.log(sum(1));
console.log(sum(5));
console.log(sum(9));
console.log(sum(10));
Interview Question: Sum
Conquer the JavaScript Interview: Cumulative Sum [Beginner Skill Level]
Interview Question: Three Sum
Big Finance Coding Interview Question - Minimum Value to Get Positive Step by Step Sum