Skip to content

Commit 735d836

Browse files
committed
updates
1 parent 6fff01a commit 735d836

2 files changed

Lines changed: 110 additions & 9 deletions

File tree

04 - Array Cardio Day 1/index-START.html

Lines changed: 65 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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();

pieFactory.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//You are working at a pie factory and want to pass the time. You assign a numerical value to each pie of the following
2+
//[{type: 'Cherry', value: 1}, {type: 'Blueberry', value: 2},{type: 'Strawberry', value: 3}, {type: 'Raspberry', value: 5}, {type: 'Blackberry', value: -1}, {type: 'Apple', value: 13 }]
3+
4+
//Create a function that takes an array of pies, looks up their numerical value,
5+
//and returns an array where each value in the array is the sum of itself and all the previous numbers in the array
6+
7+
//example [cherry, blueberry, strawberry] would equal to [1, 3, 6]
8+
//if the array is empty they retun an empty array
9+
10+
11+
//First place information into an array
12+
const pies = [
13+
{type: 'Cherry', value: 1},
14+
{type: 'Blueberry', value: 2},
15+
{type: 'Strawberry', value: 3},
16+
{type: 'Raspberry', value: 5},
17+
{type: 'Blackberry', value: -1},
18+
{type: 'Apple', value: 13 }
19+
];
20+
21+
//second only access the values
22+
const pieValues = pies.filter(function(number){
23+
return number[1].value;
24+
});
25+
26+
console.log(pieValues);
27+
28+
function solution (pies) {
29+
// Type your solution here
30+
//function needs to look up value
31+
//return an array
32+
if (pies === undefined || pies.length == 0){
33+
return [];
34+
} else {
35+
alert(`here`);
36+
37+
38+
// valuesFromPies.reduce(function (previous, current){
39+
// return previous + current
40+
// });
41+
42+
}
43+
};
44+
45+
solution();

0 commit comments

Comments
 (0)