Skip to content

Commit c8f1c42

Browse files
homework_7
1 parent be38ff9 commit c8f1c42

File tree

2 files changed

+123
-0
lines changed

2 files changed

+123
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Home work 7</title>
6+
</head>
7+
<body>
8+
9+
<script src="src/main.js"></script>
10+
</body>
11+
</html>
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
//Task1
2+
function add(arg1) {
3+
let value1 = arg1;
4+
return function (arg2) {
5+
let value2 = arg2;
6+
return function (arg3) {
7+
let value3 = arg3;
8+
return value1 = value1 + value2 + value3;
9+
};
10+
};
11+
};
12+
13+
console.log('Task1 ', add(1)(2)(3)); // 6
14+
console.log('Task1 ', add(10)(5)(15)); // 30
15+
16+
17+
18+
//Task2
19+
function patternModule() {
20+
let count = 0;
21+
return {
22+
method: function () {
23+
return count += 1;
24+
},
25+
setToZero: function() {
26+
return count = 0;
27+
}
28+
};
29+
};
30+
31+
//patternModule
32+
33+
let test = patternModule(); // 0
34+
console.log('Task2 ', test.method()); //1
35+
console.log('Task2 ', test.method()); //2
36+
console.log('Task2 ', test.method()); //3
37+
console.log('Task2 ', test.setToZero());
38+
console.log('Task2 ', test.method());
39+
40+
41+
42+
43+
//Task3
44+
let jun = {};
45+
46+
function methodCounter(obj, name, num, fn) {
47+
let counter = 0;
48+
obj[name] = function(...args) {
49+
if(counter < num) {
50+
counter += 1;
51+
return `Call number ${counter}, sum of arguments = ${fn(args)}`;
52+
} else {
53+
return 'ERROR ! add more methods';
54+
}
55+
}
56+
};
57+
58+
methodCounter(jun, 'logger', 2, function (args) {
59+
let sumArgs = 0;
60+
for (let i = 0; i < args.length; i++) {
61+
sumArgs = sumArgs + args[i];
62+
};
63+
return sumArgs;
64+
});
65+
66+
console.log('Task3 ', jun.logger(1, 2, 3, 4)); // 2, 10
67+
console.log('Task3 ', jun.logger(5, 5, 5, 5)); // 1, 20
68+
console.log('Task3 ', jun.logger(5, 5)); // ERROR ! add more methods
69+
70+
//Super
71+
let jun2 = {};
72+
73+
function methodCounter2(obj, name, num, fn) {
74+
let counter = num;
75+
obj[name] = function(...args) {
76+
if(counter > 0) {
77+
counter -= 1;
78+
return `Call number ${counter + 1}, sum of arguments = ${fn(args)}`;
79+
} else {
80+
return 'ERROR ! add more methods';
81+
};
82+
};
83+
obj.addCounter = function(initialCounter) {
84+
return counter = initialCounter;
85+
};
86+
};
87+
88+
let methodName = methodCounter2(jun2, 'logger', 2, function (args) {
89+
let sumArgs = 0;
90+
for (let i = 0; i < args.length; i++) {
91+
sumArgs = sumArgs + args[i];
92+
};
93+
return sumArgs;
94+
});
95+
console.log('Super ', jun2.addCounter(10, methodName));
96+
console.log('Super ', jun2.logger(1, 2, 3, 4));
97+
console.log('Super ', jun2.logger(1, 2, 3, 4));
98+
console.log('Super ', jun2.logger(1, 2, 3, 4));
99+
console.log('Super ', jun2.logger(1, 2, 3, 4));
100+
console.log('Super ', jun2.logger(1, 2, 3, 4));
101+
console.log('Super ', jun2.logger(1, 2, 3, 4));
102+
console.log('Super ', jun2.logger(1, 2, 3, 4));
103+
console.log('Super ', jun2.logger(1, 2, 3, 4));
104+
console.log('Super ', jun2.logger(1, 2, 3, 4));
105+
console.log('Super ', jun2.logger(1, 2, 3, 4));
106+
console.log('Super ', jun2.logger(1, 2, 3, 4));
107+
console.log('Super ', jun2.logger(1, 2, 3, 4));
108+
console.log('Super ', jun2.addCounter(3, methodName));
109+
console.log('Super ', jun2.logger(1, 2, 3, 4));
110+
console.log('Super ', jun2.logger(1, 2, 3, 4));
111+
console.log('Super ', jun2.logger(1, 2, 3, 4));
112+
console.log('Super ', jun2.logger(1, 2, 3, 4));

0 commit comments

Comments
 (0)