@@ -94,5 +94,105 @@ console.log(val)
9494}
9595bilal ( 1 , 2 , 3 , 4 ) ;
9696
97+ //que 1
98+ //concat two arrays fetched from two diff apis
99+ //concat is just mix or paste two arrays into one
100+ //interview que
97101
102+ let concat1 = [ "raima" , "maria" , "andleeb" ] ;
103+ let concat2 = [ "ali" , "adnan" , "mubashir" ] ;
104+
105+ let students = [ ...concat1 , ...concat2 ]
106+ console . log ( students ) ;
107+
108+ //if i have to merge then I should have a logic
109+ let topstudents = concat1 . concat ( concat2 ) . sort ( ) //logic is sorting according to alphabetical order
110+ console . log ( topstudents )
111+
112+ //Custom Sorting with Comparator Function:
113+
114+ let num1 = [ 3 , 4 , 1 , 3 , 70 ]
115+
116+ let sortednum1 = num1 . sort ( ( a , b ) => a - b )
117+ console . log ( sortednum1 )
118+
119+ let num2 = [ 20 , 60 , 5 , 3 ]
120+ let arr = num1 . concat ( num2 ) . sort ( ( a , b ) => a - b ) ;
121+ console . log ( arr ) ;
122+
123+ let arr1 = [ ...num1 , ...num2 ] . sort ( ( a , b ) => a - b )
124+ console . log ( arr1 ) ;
125+
126+ //que2
127+ //filter an array of obj to display item based on search query eg filter prod by type
128+ let products = [
129+ { name :"phone" , type :"electronic" } ,
130+ { name :"pen" , type :"stationary" } ,
131+ { name :"computer" , type :"electronic" } ,
132+ { name :"hairbrush" , type :"beauty" } ,
133+ { name :"jacket" , type :"clothing" }
134+
135+ ]
136+
137+ let search = products . filter ( ( product ) => {
138+ return product . type === 'beauty'
139+ } ) . map ( ( product ) => {
140+ return product . name
141+ } )
142+
143+
144+ console . log ( search )
145+
146+ //que3
147+ //map array of obj and display on div
148+
149+ let lastname = [
150+ { name :"kamran" , type :"boy" } ,
151+ { name :"bilal" , type :"boy" } ,
152+ { name :"alina" , type :"girl" } ,
153+ { name :"momina" , type :"girl" } ,
154+ ]
155+ // lastname.map((name)=>{
156+ // return (
157+ // <div> <h1>{name.type} </h1> </div>
158+ // )
159+
160+ // })
161+
162+ //que4
163+ //
164+ let relatives = [
165+ { name :"phupo" , percen :"1%" , type :"notimmed" } ,
166+ { name :"mamoo" , percen :"30%" , type :"notimmed" } ,
167+ { name :"khala" , percen :"80%" , type :"notimmed" } ,
168+ { name :"father" , percen :"0%" , type :"immed" } ,
169+ ]
170+
171+ let object = { }
172+ relatives . forEach ( ( relative ) => {
173+ if ( object [ relative . type ] ) {
174+ object [ relative . type ] . push ( relative )
175+
176+ } else {
177+ object [ relative . type ] = [ ]
178+ object [ relative . type ] . push ( relative )
179+ }
180+ } )
181+
182+ console . log ( object )
183+
184+
185+ //que5
186+ //if you want to remove an obj from array
187+
188+ let countries = [
189+ { name :"Japan" , id :1 } ,
190+ { name :"China" , id :2 } ,
191+ { name :"Canda" , id :3 } ,
192+ { name :"Korea" , id :4 } ,
193+ ]
194+ let updated_countries = countries . filter ( ( country ) => {
195+ return country . id !== 3
196+ } )
197+ console . log ( updated_countries )
98198
0 commit comments