Visitar URL original
completed w/ video · wesbos/JavaScript30@a29429b · GitHub
Skip to content

Commit a29429b

Browse files
committed
completed w/ video
1 parent 656c97a commit a29429b

1 file changed

Lines changed: 62 additions & 5 deletions

File tree

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

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,91 @@
2121
{ first: 'Max', last: 'Planck', year: 1858, passed: 1947 }
2222
];
2323

24-
const flavours = ['Chocolate Chip', 'Kulfi', 'Caramel Praline', 'Chocolate', 'Burnt Caramel', 'Pistachio', 'Rose', 'Sweet Coconut', 'Lemon Cookie', 'Toffeeness', 'Toasted Almond', 'Black Raspberry Crunch', 'Chocolate Brownies', 'Pistachio Almond', 'Strawberry', 'Lavender Honey', 'Lychee', 'Peach', 'Black Walnut', 'Birthday Cake', 'Mexican Chocolate', 'Mocha Almond Fudge', 'Raspberry'];
25-
26-
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'];
27-
2824
// Array.prototype.filter()
2925
// 1. Filter the list of inventors for those who were born in the 1500's
3026

27+
const fifteen = inventors.filter(inventor => (inventor.year >= 1500 && inventor.year <= 1600));
28+
// console.table(fifteen);
29+
3130
// Array.prototype.map()
3231
// 2. Give us an array of the inventory first and last names
3332

33+
const fullName = inventors.map(inventor => (inventor.first + ' ' +inventor.last));
34+
// console.log(fullName);
35+
36+
const inventorName = inventors.map(inventor => inventor.first + ' ' + inventor.last);
37+
// console.log(inventorName);
38+
39+
3440
// Array.prototype.sort()
3541
// 3. Sort the inventors by birthdate, oldest to youngest
3642

43+
const birth = inventors.sort(function(a, b) {
44+
if (a.year >= b.year) {
45+
return 1;
46+
} else {
47+
return -1;
48+
}
49+
});
50+
// console.table(birth);
51+
52+
53+
//Short Hand
54+
const birthYear = inventors.sort((a, b) => a.year >= b.year ? 1 : -1);
55+
// console.table(birthYear);
56+
57+
3758
// Array.prototype.reduce()
3859
// 4. How many years did all the inventors live?
60+
const totalYears = inventors.reduce((total, inventor) => {
61+
return total + (inventor.passed - inventor.year);
62+
}, .0 );
63+
// console.log(totalYears);
3964

4065
// 5. Sort the inventors by years lived
66+
const oldest = inventors.sort((a,b) => {
67+
const lastGuy = a.passed - a.year;
68+
const nextGuy = b.passed - b.year;
69+
return nextGuy > lastGuy ? 1 : -1;
70+
});
71+
// console.table(oldest);
4172

4273
// 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name
4374
// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
75+
// const category = document.querySelector('.mw-category');
76+
// const links = Array.from(category.querySelectorAll('a'));
77+
//
78+
// const de = links
79+
// .map(link => link.textContent)
80+
// .filter(streetName => streetName.includes('de'));
81+
82+
4483

84+
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'];
4585

4686
// 7. sort Exercise
4787
// Sort the people alphabetically by last name
88+
const lastName= people.sort(function(lastOne, nextOne) {
89+
const [aLast, aFirst] = lastOne.split (', ');
90+
const [bLast, bFirst] = nextOne.split (', ');
91+
return aLast > bLast ? 1 : -1;
92+
});
93+
// console.log(lastName);
94+
95+
4896

4997
// 8. Reduce Exercise
5098
// Sum up the instances of each of these
51-
const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ];
99+
const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'motorcycle', 'van', 'bike', 'walk', 'motorcycle', 'car', 'van', 'car', 'truck', 'hoverBoard' ];
100+
101+
const transportation = data.reduce(function(obj,item){
102+
if(!obj[item]){
103+
obj[item] = 0;
104+
}
105+
obj[item]++;
106+
return obj;
107+
}, {});
108+
console.log(transportation);
52109

53110
</script>
54111
</body>

0 commit comments

Comments
 (0)