Skip to content

Commit bcd5bb3

Browse files
homework_6
1 parent 29f4c2f commit bcd5bb3

File tree

2 files changed

+201
-0
lines changed

2 files changed

+201
-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 6</title>
6+
</head>
7+
<body>
8+
9+
<script src="src/main.js"></script>
10+
</body>
11+
</html>
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
//Task1
2+
3+
let randomString = 'aaa b a w c ';
4+
5+
let user = {
6+
name: 'Albina',
7+
};
8+
9+
let javaScript = {
10+
html: 'JavaScript',
11+
};
12+
13+
function countLetterA(str) {
14+
let counter = 0;
15+
let arrStr = str.split('');
16+
arrStr.forEach(function(elem, index, arr) {
17+
if (elem === 'a') {
18+
counter++;
19+
};
20+
return counter;
21+
});
22+
return counter;
23+
};
24+
25+
console.log('Task1 ', countLetterA(randomString));
26+
console.log('Task1 ', countLetterA(javaScript.html + user.name));
27+
28+
29+
30+
//Task2
31+
32+
function reverseEachWord(str) {
33+
let arrStr = str.split(' ');
34+
let newArrStr = [];
35+
arrStr.forEach(function(elem, index, arr) {
36+
let arrElem = elem.split('');
37+
let reversElemInArr = arrElem.reverse();
38+
let reversElemInString = reversElemInArr.join('');
39+
newArrStr.push(reversElemInString);
40+
});
41+
return newArrStr.join(' ');
42+
};
43+
44+
console.log('Task2 ', reverseEachWord('You don\'t have to do anything special to begin using the DOM. Different browsers have different implementations of the DOM'));
45+
console.log('Task2 ', reverseEachWord('The Document Object Model (DOM) is a programming interface for HTML and XML documents'));
46+
47+
48+
49+
//Task3
50+
51+
function reverseEachWord2(str, boolean) {
52+
let arrStr = str.split(' ');
53+
let newArrStr = [];
54+
arrStr.forEach(function(elem, index, arr) {
55+
let arrElem = elem.split('');
56+
let reversElemInArr = arrElem.reverse();
57+
let reversElemInString = reversElemInArr.join('');
58+
newArrStr.push(reversElemInString);
59+
});
60+
if (boolean === true) {
61+
newArrStr.reverse();
62+
};
63+
return newArrStr.join(' ');
64+
};
65+
66+
console.log('Task3 ', reverseEachWord2('The Document Object Model (DOM) is a programming interface for HTML and XML documents', true));
67+
console.log('Task3 ', reverseEachWord2('Hi my Name is', false));
68+
console.log('Task3 ', reverseEachWord2('Hi my Name is', true));
69+
70+
71+
72+
73+
//Task4
74+
75+
function wordCounter(sentence) {
76+
let arrayOfSentences = sentence.split(' ');
77+
let elements = arrayOfSentences.reduce(function(newValue, elem, index, arr) {
78+
let initialElem = elem;
79+
let counter = 0;
80+
arrayOfSentences.forEach(function(elem, index, arr) {
81+
if (initialElem === elem) {
82+
counter++;
83+
};
84+
});
85+
newValue[initialElem] = counter;
86+
return newValue;
87+
}, {});
88+
return elements;
89+
};
90+
91+
console.log('Task4 ', wordCounter('Both Java and Java Script is programming and programming OOPBased Language'));
92+
93+
94+
95+
96+
//Task5
97+
98+
let listOfCompanys = [
99+
{
100+
company: 'ASIMILINE',
101+
name: {
102+
last: 'Watkins',
103+
first: 'Lindsay',
104+
},
105+
eyeColor: 'brown',
106+
age: 20,
107+
picture: 'http://placehold.it/32x32',
108+
balance: '$1,091.09',
109+
isActive: true,
110+
guid: '294814e3-4c89-428f-b0c9-da5c4c37ea5e',
111+
index: 0,
112+
_id: '584babb6eeb4137cf14c37a3',
113+
},
114+
{
115+
company: 'ENJOLA',
116+
name: {
117+
last: 'Price',
118+
first: 'Greene',
119+
},
120+
eyeColor: 'brown',
121+
age: 39,
122+
picture: 'http://placehold.it/32x32',
123+
balance: '$3,533.55',
124+
isActive: true,
125+
guid: 'e7b0824f-d6d1-4a82-b2c5-cd7a1ec8310c',
126+
index: 1,
127+
_id: '584babb6c7be9c2398ed263f',
128+
},
129+
{
130+
company: 'ZINCA',
131+
name: {
132+
last: 'Robertson',
133+
first: 'Barbara',
134+
},
135+
eyeColor: 'brown',
136+
age: 22,
137+
picture: 'http://placehold.it/32x32',
138+
balance: '$1,395.22',
139+
isActive: false,
140+
guid: '0735d8d9-a165-4ad1-893f-e821da37bf63',
141+
index: 2,
142+
_id: '584babb6cca4dbefa6001820',
143+
},
144+
{
145+
company: 'TALKOLA',
146+
name: {
147+
last: 'Cooke',
148+
first: 'Lea',
149+
},
150+
eyeColor: 'blue',
151+
age: 31,
152+
picture: 'http://placehold.it/32x32',
153+
balance: '$3,074.16',
154+
isActive: false,
155+
guid: '7d13cbc4-6b4d-4954-b3d3-df3cfe5f2373',
156+
index: 3,
157+
_id: '584babb6391a2b568f1e9416',
158+
},
159+
{
160+
company: 'GEEKKO',
161+
name: {
162+
last: 'Webb',
163+
first: 'Kline',
164+
},
165+
eyeColor: 'blue',
166+
age: 34,
167+
picture: 'http://placehold.it/32x32',
168+
balance: '$1,520.21',
169+
isActive: false,
170+
guid: '2b179de0-a659-4423-b3c4-11c6490e5c74',
171+
index: 4,
172+
_id: '584babb66d6ea73e8ed51208',
173+
},
174+
];
175+
176+
function createHashTags(arr) {
177+
let ogj = arr.reduce(function(newValue, elem, index, arr) {
178+
let elemKey = elem._id;
179+
let elemValue = elem.company;
180+
newValue[elemKey] = elemValue;
181+
return newValue;
182+
}, {});
183+
return ogj;
184+
}
185+
186+
console.log('Task5 ',createHashTags(listOfCompanys));
187+
188+
//@ SUPER1
189+
190+
//@ SUPER2

0 commit comments

Comments
 (0)