@@ -77,41 +77,61 @@ console.log(test.method()); //3
7777
7878let jun = { } ;
7979
80- function methodCounter ( obj , name , num , fn ) {
81- obj [ name ] = fn ;
82- obj . counter = num ;
83- obj . addCounter = function ( quantity ) {
84- obj . counter += quantity ;
85- return console . log ( `Counter was replenished on ${ obj . counter } ` ) ;
86- } ;
87- return function ( ) {
88- return obj ;
89- } ;
90- }
80+ //function methodCounter(obj, name, num, fn) {
81+ // obj[name] = fn;
82+ // obj.counter = num;
83+ // obj.addCounter = function (quantity) {
84+ // obj.counter += quantity;
85+ // return console.log(`Counter was replenished on ${obj.counter}`);
86+ // };
87+ // return function () {
88+ // return obj;
89+ // };
90+ //}
91+ //
92+ //function sumLogger () {
93+ // let arrayWithArguments = [...arguments];
94+ //
95+ // if(jun.counter > 0) {
96+ // --jun.counter;
97+ //
98+ // const sumArguments = arrayWithArguments.reduce(function(newValue, value) {
99+ // return newValue + value;
100+ // }, 0);
101+ //
102+ // return console.log(`You can use this method else: ${jun.counter}; sum of arguments equal: ${sumArguments}.`);
103+ //
104+ // } else {
105+ // return console.log(`ERROR ! add more methods`);
106+ // }
107+ //}
108+ let counter = null ;
91109
92- function sumLogger ( ) {
93- let arrayWithArguments = [ ...arguments ] ;
94-
95- if ( jun . counter > 0 ) {
96- -- jun . counter ;
97-
98- const sumArguments = arrayWithArguments . reduce ( function ( newValue , value ) {
99- return newValue + value ;
100- } , 0 ) ;
101-
102- return console . log ( `You can use this method else: ${ jun . counter } ; sum of arguments equal: ${ sumArguments } .` ) ;
103-
104- } else {
105- return console . log ( `ERROR ! add more methods` ) ;
110+ function methodCounter ( obj , name , num , fn ) {
111+ let func = fn ;
112+ 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 ) {
119+ return console . log ( `ERROR ! add more methods` ) ;
120+ }
106121 }
107122}
108123
124+ methodCounter ( jun , 'logger' , 2 , function ( args ) {
125+ let arrayWithArguments = [ ...arguments ] ;
126+ const sumArguments = arrayWithArguments . reduce ( function ( newValue , value ) {
127+ return newValue + value ;
128+ } , 0 ) ;
129+ return sumArguments ;
130+ } ) ;
109131
110- methodCounter ( jun , 'logger' , 2 , sumLogger ) ;
111-
112- jun . logger ( 1 , 2 , 3 , 4 ) ; // 2, 10
113- jun . logger ( 5 , 5 , 5 , 5 ) ; // 1, 20
114- jun . logger ( 5 , 5 ) ; // ERROR ! add more methods
132+ console . log ( jun . logger ( 1 , 2 , 3 , 4 ) ) ; // 2, 10
133+ console . log ( jun . logger ( 5 , 5 , 5 , 5 ) ) ; // 1, 20
134+ console . log ( jun . logger ( 5 , 5 ) ) ; // ERROR ! add more methods
115135
116136// @SUPER ,
117137
@@ -121,5 +141,5 @@ jun.logger(5, 5); // ERROR ! add more methods
121141 *
122142 * */
123143
124- jun . addCounter ( 10 ) ;
125- jun . logger ( 5 , 5 ) ;
144+ // jun.addCounter(10);
145+ // jun.logger(5, 5);
0 commit comments