Skip to content

Commit 579abdf

Browse files
Balashov NikitaOlegLustenko
authored andcommitted
lesson-8
1 parent 0250b06 commit 579abdf

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Class work 8</title>
6+
</head>
7+
<body>
8+
<script src="src/main.js"></script>
9+
</body>
10+
</html>
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
function checkActionType(action) {
2+
switch(action.type){
3+
case(`INITIALIZE`):
4+
return {initialized: true};
5+
case(`INCREMENT`):
6+
return {salary: `+500$`};
7+
case(`DECREMENT`):
8+
return {salary: `-500$`};
9+
}
10+
}
11+
12+
console.log(checkActionType({type: `INITIALIZE`}));
13+
console.log(checkActionType({type: `INCREMENT`}));
14+
console.log(checkActionType({type: `DECREMENT`}));
15+
16+
// TASK 1
17+
18+
function sumArguments() {
19+
const argumentsTheFunc = [...arguments];
20+
const sum = argumentsTheFunc.reduce(function(newValue, value) {
21+
return newValue + value;
22+
}, 0)
23+
return sum;
24+
}
25+
26+
function sumArguments2() {
27+
let zero = 0;
28+
for(let i = 0; i < arguments.length; i++) {
29+
zero += arguments[i];
30+
}
31+
return zero;
32+
}
33+
console.log(sumArguments2(12, 13, 14));
34+
35+
console.log(sumArguments(10, 12, 12, 12, 12, 23, 23, 44));
36+
console.log(sumArguments(10, 12));
37+
38+
console.log(sumArguments(10, 12, 12, 12, 12, 23, 23, 44, 12, 32, 43, 32));
39+
40+
// TASK 2
41+
42+
const user = {
43+
id: 10,
44+
city: `Tailand`,
45+
email: `example@example.com`,
46+
cars: {
47+
id: 20,
48+
names: [`bmw`, `VAZ`, `mercedes`, `AUDI`],
49+
venders: {
50+
id: 30,
51+
adreses: [`google`, `yahoo`],
52+
}
53+
},
54+
};
55+
56+
function copyObject(obj) {
57+
// for(let key in obj) {
58+
// newObj[key] = obj[key];
59+
// }
60+
// newObj.city = `Kharkiv`;
61+
/* version 1 */
62+
// return Object.assign({}, obj, {cars: [...obj.cars]});
63+
/* version 2 */
64+
const newObj = {
65+
...obj,
66+
cars:{
67+
...obj.cars,
68+
names: [...obj.cars.names],
69+
venders: {
70+
...obj.cars.venders,
71+
adreses: [...obj.cars.venders.adreses],
72+
}},
73+
};
74+
return newObj;
75+
}
76+
77+
const newUser = copyObject(user);
78+
newUser.cars.names.push(`Juguli`);
79+
newUser.cars.venders.adreses.push(`mAIL.rU`);
80+
console.log(newUser);
81+
console.log(user);
82+
83+
console.log(sumArguments(10, 12, 12, 12, 12, 23, 23, 44, 12, 32, 43, 32));
84+

0 commit comments

Comments
 (0)