Skip to content

Commit 1bd32a5

Browse files
committed
adding script wesbos#4
1 parent 250626c commit 1bd32a5

File tree

1 file changed

+35
-9
lines changed

1 file changed

+35
-9
lines changed

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

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,55 @@
3131

3232
// Array.prototype.filter()
3333
// 1. Filter the list of inventors for those who were born in the 1500's
34-
34+
const fifteen = inventors.filter(inventor => (inventor.year >= 1500 && inventor.year <= 1600));
35+
console.table(fifteen);
3536
// Array.prototype.map()
3637
// 2. Give us an array of the inventors' first and last names
37-
38+
const fullNames = inventors.map(inventor => `${inventor.first} ${inventor.last}`);
39+
console.log(fullNames);
3840
// Array.prototype.sort()
3941
// 3. Sort the inventors by birthdate, oldest to youngest
40-
42+
const ordered = inventors.sort((a,b) => a.year > b.year ? 1: -1);
43+
console.table(ordered);
4144
// Array.prototype.reduce()
4245
// 4. How many years did all the inventors live?
43-
46+
const totalYears = inventors.reduce((total, inventor) =>{
47+
return total + (inventor.passed - inventor.year);
48+
}, 0);
49+
console.log(totalYears);
4450
// 5. Sort the inventors by years lived
45-
51+
const oldest = inventors.sort(function(a,b){
52+
const lastGuy = a.padded - a.year;
53+
const nextGuy = b.passed - b.year;
54+
return lastGuy > nextGuy ? -1 : 1;
55+
})
56+
console.table(oldest);
4657
// 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name
4758
// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
48-
49-
59+
// const category = document.querySelector('.mw-category');
60+
// const links = Array.from(category.querySelectorAll('a'));
61+
// const de = links
62+
// .map(link => link.textContent)
63+
// .filter(streetName => streetName.includes('de'));
5064
// 7. sort Exercise
5165
// Sort the people alphabetically by last name
52-
66+
const alpha = people.sort((lastOne, nextOne) => {
67+
const [aLast, aFirst] = lastOne.split(',');
68+
const [bLast, bFirst] = nextOne.split(',');
69+
return aLast > bLast ? 1 : -1;
70+
})
71+
console.log(alpha);
5372
// 8. Reduce Exercise
5473
// Sum up the instances of each of these
5574
const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ];
56-
75+
const transportation = data.reduce(function(obj, item){
76+
if(!obj[item]) {
77+
obj[item] = 0;
78+
}
79+
obj[item]++;
80+
return obj;
81+
}, {})
82+
console.log(transportation);
5783
</script>
5884
</body>
5985
</html>

0 commit comments

Comments
 (0)