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 arrStr = str . split ( '' ) ;
15+ let countLetterA2 = arrStr . reduce ( function ( newElem , elem ) {
16+ if ( elem === 'a' ) {
17+ newElem ++ ;
18+ } ;
19+ return newElem ;
20+ } , 0 ) ;
21+ return countLetterA2 ;
22+ } ;
23+ console . log ( 'Task1 ' , countLetterA ( randomString ) ) ;
24+ console . log ( 'Task1 ' , countLetterA ( javaScript . html + user . name ) ) ;
25+
26+
27+
28+
29+ //Task2
30+
31+ function reverseEachWord ( str ) {
32+ let arrStr = str . split ( ' ' ) ;
33+ let newArrStr = [ ] ;
34+ arrStr . forEach ( function ( elem ) {
35+ let arrElem = elem . split ( '' ) ;
36+ let reversElemInArr = arrElem . reverse ( ) ;
37+ let reversElemInString = reversElemInArr . join ( '' ) ;
38+ newArrStr . push ( reversElemInString ) ;
39+ } ) ;
40+ return newArrStr . join ( ' ' ) ;
41+ } ;
42+
43+ 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' ) ) ;
44+ console . log ( 'Task2 ' , reverseEachWord ( 'The Document Object Model (DOM) is a programming interface for HTML and XML documents' ) ) ;
45+
46+
47+
48+ //Task3
49+
50+ function reverseEachWord2 ( str , shouldReverse ) {
51+ let arrStr = str . split ( ' ' ) ;
52+ let newArrStr = [ ] ;
53+ arrStr . forEach ( function ( elem ) {
54+ let arrElem = elem . split ( '' ) ;
55+ let reversElemInArr = arrElem . reverse ( ) ;
56+ let reversElemInString = reversElemInArr . join ( '' ) ;
57+ newArrStr . push ( reversElemInString ) ;
58+ } ) ;
59+ if ( shouldReverse === true ) {
60+ newArrStr . reverse ( ) ;
61+ } ;
62+ return newArrStr . join ( ' ' ) ;
63+ } ;
64+
65+ console . log ( 'Task3 ' , reverseEachWord2 ( 'The Document Object Model (DOM) is a programming interface for HTML and XML documents' , true ) ) ;
66+ console . log ( 'Task3 ' , reverseEachWord2 ( 'Hi my Name is' , false ) ) ;
67+ console . log ( 'Task3 ' , reverseEachWord2 ( 'Hi my Name is' , true ) ) ;
68+
69+
70+
71+
72+ //Task4
73+
74+ function wordCounter2 ( sentence ) {
75+ let arrayOfSentences = sentence . split ( ' ' ) ;
76+ let elements = arrayOfSentences . reduce ( function ( newValue , elem ) {
77+ newValue [ elem ] = newValue [ elem ] ? newValue [ elem ] + 1 : 1 ;
78+ return newValue ;
79+ } , { } ) ;
80+ return elements ;
81+ } ;
82+ console . log ( 'Task4 ' , wordCounter2 ( 'Both Java and Java Script is programming and programming OOPBased Language' ) ) ;
83+
84+
85+
86+ //Task5
87+
88+ let listOfCompanys = [
89+ {
90+ company : 'ASIMILINE' ,
91+ name : {
92+ last : 'Watkins' ,
93+ first : 'Lindsay' ,
94+ } ,
95+ eyeColor : 'brown' ,
96+ age : 20 ,
97+ picture : 'http://placehold.it/32x32' ,
98+ balance : '$1,091.09' ,
99+ isActive : true ,
100+ guid : '294814e3-4c89-428f-b0c9-da5c4c37ea5e' ,
101+ index : 0 ,
102+ _id : '584babb6eeb4137cf14c37a3' ,
103+ } ,
104+ {
105+ company : 'ENJOLA' ,
106+ name : {
107+ last : 'Price' ,
108+ first : 'Greene' ,
109+ } ,
110+ eyeColor : 'brown' ,
111+ age : 39 ,
112+ picture : 'http://placehold.it/32x32' ,
113+ balance : '$3,533.55' ,
114+ isActive : true ,
115+ guid : 'e7b0824f-d6d1-4a82-b2c5-cd7a1ec8310c' ,
116+ index : 1 ,
117+ _id : '584babb6c7be9c2398ed263f' ,
118+ } ,
119+ {
120+ company : 'ZINCA' ,
121+ name : {
122+ last : 'Robertson' ,
123+ first : 'Barbara' ,
124+ } ,
125+ eyeColor : 'brown' ,
126+ age : 22 ,
127+ picture : 'http://placehold.it/32x32' ,
128+ balance : '$1,395.22' ,
129+ isActive : false ,
130+ guid : '0735d8d9-a165-4ad1-893f-e821da37bf63' ,
131+ index : 2 ,
132+ _id : '584babb6cca4dbefa6001820' ,
133+ } ,
134+ {
135+ company : 'TALKOLA' ,
136+ name : {
137+ last : 'Cooke' ,
138+ first : 'Lea' ,
139+ } ,
140+ eyeColor : 'blue' ,
141+ age : 31 ,
142+ picture : 'http://placehold.it/32x32' ,
143+ balance : '$3,074.16' ,
144+ isActive : false ,
145+ guid : '7d13cbc4-6b4d-4954-b3d3-df3cfe5f2373' ,
146+ index : 3 ,
147+ _id : '584babb6391a2b568f1e9416' ,
148+ } ,
149+ {
150+ company : 'GEEKKO' ,
151+ name : {
152+ last : 'Webb' ,
153+ first : 'Kline' ,
154+ } ,
155+ eyeColor : 'blue' ,
156+ age : 34 ,
157+ picture : 'http://placehold.it/32x32' ,
158+ balance : '$1,520.21' ,
159+ isActive : false ,
160+ guid : '2b179de0-a659-4423-b3c4-11c6490e5c74' ,
161+ index : 4 ,
162+ _id : '584babb66d6ea73e8ed51208' ,
163+ } ,
164+ ] ;
165+
166+ function createHashTags ( arr ) {
167+ let ogj = arr . reduce ( function ( newValue , elem , index , arr ) {
168+ let elemKey = elem . _id ;
169+ let elemValue = elem . company ;
170+ newValue [ elemKey ] = elemValue ;
171+ return newValue ;
172+ } , { } ) ;
173+ return ogj ;
174+ }
175+
176+ console . log ( 'Task5 ' , createHashTags ( listOfCompanys ) ) ;
177+
178+ //@ SUPER1
179+ let notUniqArray = [ 1 , 1 , 2 , 2 , 2 , 5 , 10 , 25 , 30 , 5 , 1 , 0 , 22 , 3 , 10 , 3 ] ;
180+
181+ function uniqueElements ( arr ) {
182+ let uniqueElements = [ ] ;
183+ nextInput:
184+ for ( let i = 0 ; i < arr . length ; i ++ ) {
185+ let initialElem = arr [ i ] ;
186+ for ( let k = 0 ; k < uniqueElements . length ; k ++ ) {
187+ if ( uniqueElements [ k ] == initialElem ) {
188+ continue nextInput;
189+ } ;
190+ } ;
191+ uniqueElements . push ( initialElem ) ;
192+ } ;
193+ return uniqueElements ;
194+ } ;
195+
196+ console . log ( 'SUPER1 ' , uniqueElements ( notUniqArray ) ) ;
197+
198+
199+ //@ SUPER2
200+ let array = [ 1 , - 1 , 0 , 15 , - 59 , 7 ] ;
201+ function filter ( callback , arr ) {
202+ let newArr = [ ] ;
203+ for ( let i = 0 ; i < arr . length ; i ++ ) {
204+ if ( ! callback ( arr [ i ] ) ) {
205+ continue ;
206+ } ;
207+ newArr . push ( arr [ i ] ) ;
208+ } ;
209+ return newArr ;
210+ } ;
211+
212+ let res = function exampleCallbackFunction ( value ) {
213+ return value < 0 ;
214+ } ;
215+
216+ console . log ( 'SUPER2 ' , filter ( res , array ) ) ;
0 commit comments