Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d427e6f

Browse files
committed
wesbos#4 done
1 parent c7db526 commit d427e6f

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,57 @@
2727

2828
// Array.prototype.filter()
2929
// 1. Filter the list of inventors for those who were born in the 1500's
30+
let inventorsOf1500 = inventors.filter((inventor) => (inventor.year < 1600 && inventor.year >= 1500));
31+
console.table(inventorsOf1500);
3032

3133
// Array.prototype.map()
3234
// 2. Give us an array of the inventory first and last names
35+
let names = inventors.map((inventor) => inventor.first + ' ' + inventor.last);
36+
console.log(names);
3337

3438
// Array.prototype.sort()
3539
// 3. Sort the inventors by birthdate, oldest to youngest
40+
let inventorsSortByBirthday = inventors.sort((inventor1, inventor2) => inventor1.year - inventor2.year);
41+
console.table(inventorsSortByBirthday);
42+
3643

3744
// Array.prototype.reduce()
3845
// 4. How many years did all the inventors live?
46+
let yearsOfAllInventors = inventors.reduce((i, inventor) => i + (inventor.passed - inventor.year), 0);
47+
console.log(yearsOfAllInventors);
3948

40-
// 5. Sort the inventors by years lived
49+
// 5. Sort the inventors by years lived highest at the beginning
50+
let inventorsByYearsLived = inventors.sort((inventor1, inventor2) => (inventor2.passed - inventor2.year) - (inventor1.passed - inventor1.year));
51+
console.table(inventorsByYearsLived);
4152

4253
// 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name
4354
// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
55+
//let category = document.querySelector('.mw-category');
56+
//let links = [...category.querySelectorAll('a')].map(a => a.textContent);
57+
//let de = links.filter(rue => rue.includes('de'));
58+
//console.log(de);
4459

4560

4661
// 7. sort Exercise
4762
// Sort the people alphabetically by last name
63+
let alphabetical = people.sort((current, next) => {
64+
let [currentLast, currentFirst] = current.split(', ');
65+
let [nextLast, nextFirst] = next.split(', ');
66+
return currentLast < nextLast ? -1 : 1;
67+
});
68+
console.log(alphabetical);
4869

4970
// 8. Reduce Exercise
5071
// Sum up the instances of each of these
5172
const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ];
73+
let numberOfAppearance = data.reduce((appearance, item) => {
74+
if(!appearance[item]) {
75+
appearance[item] = 0;
76+
}
77+
appearance[item]++;
78+
return appearance;
79+
}, {});
80+
console.log(numberOfAppearance);
5281

5382
</script>
5483
</body>

0 commit comments

Comments
 (0)