Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions sum.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
function sum() {
var agg = 0;
return function() {
agg = (arguments.length === 0)?(agg):(agg+arguments[0]);
return agg;};
}
//fn=sum();
//fn(10);
//fn(1);
//fn();
sum = (function sumFn() {
var agg = 0;

function innerAgg() {
agg = (arguments.length === 0) ? (agg) : (agg + arguments[0]);
return innerAgg;
};
innerAgg.valueOf = function() {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Как вариант, в valueOf можно обнулять значение agg

return agg;
};
return innerAgg;
})()