Skip to content

Commit dd15456

Browse files
Balashov NikitaOlegLustenko
authored andcommitted
homework-7 fix
1 parent 4425b6c commit dd15456

File tree

1 file changed

+6
-10
lines changed
  • js-core/homeworks/homework-7/src

1 file changed

+6
-10
lines changed

js-core/homeworks/homework-7/src/main.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,25 +105,21 @@ let jun = {};
105105
// return console.log(`ERROR ! add more methods`);
106106
// }
107107
//}
108-
let counter = null;
109108

110109
function methodCounter(obj, name, num, fn) {
111-
let func = fn;
112110
let counter = num;
113-
obj[name] = function() {
114-
if(counter > 0) {
115-
counter -= 1;
116-
return console.log(counter), func;
117-
}
118-
if(num === 0) {
111+
obj[name] = function(...args) {
112+
counter--;
113+
if(counter === 0) {
119114
return console.log(`ERROR ! add more methods`);
120115
}
116+
return fn(args);
121117
}
122118
}
123119

124120
methodCounter(jun, 'logger', 2, function (args){
125-
let arrayWithArguments = [...arguments];
126-
const sumArguments = arrayWithArguments.reduce(function(newValue, value) {
121+
122+
const sumArguments = args.reduce(function(newValue, value) {
127123
return newValue + value;
128124
}, 0);
129125
return sumArguments;

0 commit comments

Comments
 (0)