File tree Expand file tree Collapse file tree 1 file changed +6
-10
lines changed
js-core/homeworks/homework-7/src Expand file tree Collapse file tree 1 file changed +6
-10
lines changed Original file line number Diff line number Diff line change @@ -105,25 +105,21 @@ let jun = {};
105105// return console.log(`ERROR ! add more methods`);
106106// }
107107//}
108- let counter = null ;
109108
110109function 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
124120methodCounter ( 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 ;
You can’t perform that action at this time.
0 commit comments