@@ -89,7 +89,6 @@ <h2><a href="https://www.w3schools.com/jsref/jsref_obj_array.asp" target="_blank
8989 { first : 'Hanna' , last : 'Hammarström' , year : 1829 , passed : 1909 }
9090 ] ;
9191
92- const people = [ 'Beck, Glenn' , 'Becker, Carl' , 'Beckett, Samuel' , 'Beddoes, Mick' , 'Beecher, Henry' , 'Beethoven, Ludwig' , 'Begin, Menachem' , 'Belloc, Hilaire' , 'Bellow, Saul' , 'Benchley, Robert' , 'Benenson, Peter' , 'Ben-Gurion, David' , 'Benjamin, Walter' , 'Benn, Tony' , 'Bennington, Chester' , 'Benson, Leana' , 'Bent, Silas' , 'Bentsen, Lloyd' , 'Berger, Ric' , 'Bergman, Ingmar' , 'Berio, Luciano' , 'Berle, Milton' , 'Berlin, Irving' , 'Berne, Eric' , 'Bernhard, Sandra' , 'Berra, Yogi' , 'Berry, Halle' , 'Berry, Wendell' , 'Bethea, Erin' , 'Bevan, Aneurin' , 'Bevel, Ken' , 'Biden, Joseph' , 'Bierce, Ambrose' , 'Biko, Steve' , 'Billings, Josh' , 'Biondo, Frank' , 'Birrell, Augustine' , 'Black, Elk' , 'Blair, Robert' , 'Blair, Tony' , 'Blake, William' ] ;
9392
9493 // Array.prototype.filter()
9594 // How it works: Creates a new array with every element in an array that pass a test
@@ -158,7 +157,7 @@ <h2><a href="https://www.w3schools.com/jsref/jsref_obj_array.asp" target="_blank
158157 return person1age > person2age ? 1 : - 1 ;
159158 } ) ;
160159 //answer
161- // console.table(lifeSpan);
160+ console . table ( lifeSpan ) ;
162161
163162 // 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name
164163 // https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
@@ -170,15 +169,25 @@ <h2><a href="https://www.w3schools.com/jsref/jsref_obj_array.asp" target="_blank
170169 //Store data into an array
171170 const category = document . querySelector ( '.mw-category' ) ;
172171 const arrOfLinks = Array . from ( category . querySelectorAll ( 'a' ) ) ;
173- let de = arrOfLinks . map ( ( function ( t ) {
174- return t . textContent
175- } ) )
176- console . log ( de )
177- //answer
178-
172+ let deStreets = arrOfLinks
173+ . map ( function ( t ) { return t . textContent } )
174+ . filter ( function ( street ) { return street . includes ( 'de' ) } ) ;
175+ //answer
176+ console . log ( deStreets )
179177
180178 // 7. sort Exercise
181179 // Sort the people alphabetically by last name
180+ const people = [ 'Beck, Glenn' , 'Becker, Carl' , 'Beckett, Samuel' , 'Beddoes, Mick' , 'Beecher, Henry' , 'Beethoven, Ludwig' ,
181+ 'Begin, Menachem' , 'Belloc, Hilaire' , 'Bellow, Saul' , 'Benchley, Robert' , 'Benenson, Peter' , 'Ben-Gurion, David' , 'Benjamin, Walter' ,
182+ 'Benn, Tony' , 'Bennington, Chester' , 'Benson, Leana' , 'Bent, Silas' , 'Bentsen, Lloyd' , 'Berger, Ric' , 'Bergman, Ingmar' , 'Berio, Luciano' ,
183+ 'Berle, Milton' , 'Berlin, Irving' , 'Berne, Eric' , 'Bernhard, Sandra' , 'Berra, Yogi' , 'Berry, Halle' , 'Berry, Wendell' , 'Bethea, Erin' ,
184+ 'Bevan, Aneurin' , 'Bevel, Ken' , 'Biden, Joseph' , 'Bierce, Ambrose' , 'Biko, Steve' , 'Billings, Josh' , 'Biondo, Frank' , 'Birrell, Augustine' ,
185+ 'Black, Elk' , 'Blair, Robert' , 'Blair, Tony' , 'Blake, William' ] ;
186+
187+ const sortPeople = people . sort ( function ( a , b ) {
188+
189+ } )
190+
182191 //answer
183192
184193 // 8. Reduce Exercise
@@ -188,4 +197,51 @@ <h2><a href="https://www.w3schools.com/jsref/jsref_obj_array.asp" target="_blank
188197 </ script >
189198</ body >
190199
191- </ html >
200+ </ html >
201+
202+
203+ //You are working at a pie factory and want to pass the time. You assign a numerical value to each pie of the following
204+ //[{type: 'Cherry', value: 1}, {type: 'Blueberry', value: 2},{type: 'Strawberry', value: 3}, {type: 'Raspberry', value: 5}, {type: 'Blackberry', value: -1}, {type: 'Apple', value: 13 }]
205+
206+ //Create a function that takes an array of pies, looks up their numerical value,
207+ //and returns an array where each value in the array is the sum of itself and all the previous numbers in the array
208+
209+ //example [cherry, blueberry, strawberry] would equal to [1, 3, 6]
210+ //if the array is empty they retun an empty array
211+
212+
213+ //First place information into an array
214+ const pies = [
215+ {type: 'Cherry', value: 1},
216+ {type: 'Blueberry', value: 2},
217+ {type: 'Strawberry', value: 3},
218+ {type: 'Raspberry', value: 5},
219+ {type: 'Blackberry', value: -1},
220+ {type: 'Apple', value: 13 }
221+ ];
222+
223+ //second only access the values
224+ const pieValues = pies.filter(function(number){
225+ return number[1].value;
226+ });
227+
228+ console.log(pieValues);
229+
230+ function solution (pies) {
231+ // Type your solution here
232+ //function needs to look up value
233+ //return an array
234+ if (pies === undefined || pies.length == 0){
235+ return [];
236+ } else {
237+ alert(`here`);
238+
239+
240+ // valuesFromPies.reduce(function (previous, current){
241+ // return previous + current
242+ // });
243+
244+ }
245+ };
246+
247+ solution();
0 commit comments