Skip to content

Commit 990e867

Browse files
homework-7 fixed
1 parent 7290acf commit 990e867

File tree

1 file changed

+48
-45
lines changed
  • js-core/homeworks/homework-7/src

1 file changed

+48
-45
lines changed

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

Lines changed: 48 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
// 'use strict';
1+
'use strict';
22

3-
// /*
4-
// *
5-
// * TASK 1
6-
// *
7-
// * Напишите функцию которая будет вызываться трижды и складывать
8-
// * все передаваемые ей числа
9-
// *
10-
// * */
3+
/*
4+
*
5+
* TASK 1
6+
*
7+
* Напишите функцию которая будет вызываться трижды и складывать
8+
* все передаваемые ей числа
9+
*
10+
* */
1111

12-
// function add(x) {
13-
// return function(a){
14-
// return function(b){
15-
// return x + a + b
16-
// }
17-
// }
18-
// }
12+
function add(x) {
13+
return function(a){
14+
return function(b){
15+
return x + a + b
16+
}
17+
}
18+
}
1919

20-
// console.log(add(1)(2)(3)); // 6
21-
// console.log(add(10)(5)(15)); // 30
20+
console.log(add(1)(2)(3)); // 6
21+
console.log(add(10)(5)(15)); // 30
2222

2323
// /*
2424
// *
@@ -34,34 +34,36 @@
3434
// *
3535
// * */
3636

37-
// function patternModule(num) {
38-
// let counter = 0;
39-
// let obj = {
40-
// method: function(){
41-
// return ++counter
42-
// },
43-
// method2: function(){
44-
// return counter = 0
45-
// }
46-
// }
47-
// return obj;
37+
function patternModule(num) {
38+
let counter = 0;
39+
let obj = {
40+
method: function(){
41+
++counter
42+
return counter
43+
},
44+
method2: function(){
45+
counter = 0
46+
return counter
47+
}
48+
}
49+
return obj;
4850

49-
// }
51+
}
5052

51-
// // patternModule
53+
// patternModule
5254

53-
// let test = patternModule(); // 0
54-
// console.log(test.method()); //1
55-
// console.log(test.method()); //2
56-
// console.log(test.method()); //3
57-
// console.log(test.method()); //4
58-
// console.log(test.method()); //5
59-
// console.log(test.method()); //6
60-
// console.log(test.method2()); //0
61-
// console.log(test.method()); //1
62-
// console.log(test.method()); //2
63-
// console.log(test.method()); //3
64-
// console.log(test.method2()); //0
55+
let test = patternModule(); // 0
56+
console.log(test.method()); //1
57+
console.log(test.method()); //2
58+
console.log(test.method()); //3
59+
console.log(test.method()); //4
60+
console.log(test.method()); //5
61+
console.log(test.method()); //6
62+
console.log(test.method2()); //0
63+
console.log(test.method()); //1
64+
console.log(test.method()); //2
65+
console.log(test.method()); //3
66+
console.log(test.method2()); //0
6567

6668

6769
// /*
@@ -83,9 +85,10 @@
8385
let jun = {};
8486

8587
function methodCounter(obj, name, num, fn) {
88+
let counter = num;
8689
obj[name] = function(...args){
87-
if(num>0){
88-
return [num--, fn(args)]
90+
if(counter>0){
91+
return [counter--, fn(args)]
8992
}
9093
return `ERROR ! add more methods`
9194
}

0 commit comments

Comments
 (0)