Visitar URL original
Javascript 30-day challenge day #4 completed · baryshkov/JavaScript30@a9a4f02 · GitHub
Skip to content

Commit a9a4f02

Browse files
committed
Javascript 30-day challenge day wesbos#4 completed
1 parent 65775bf commit a9a4f02

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,76 @@
3232
// Array.prototype.filter()
3333
// 1. Filter the list of inventors for those who were born in the 1500's
3434

35+
const result = inventors.filter((elem) => elem.year >= 1500 && elem.year < 1600);
36+
console.table(result);
37+
3538
// Array.prototype.map()
3639
// 2. Give us an array of the inventors' first and last names
3740

41+
const names = inventors.map((elem) => elem.first + ' ' + elem.last);
42+
console.table(names);
43+
3844
// Array.prototype.sort()
3945
// 3. Sort the inventors by birthdate, oldest to youngest
46+
inventors.sort((a, b) => (a.year > b.year) ? 1 : -1);
47+
console.table(inventors);
4048

4149
// Array.prototype.reduce()
4250
// 4. How many years did all the inventors live?
4351

52+
const totalYears = inventors.reduce(((sum, currentValue) => {
53+
return sum + currentValue.passed - currentValue.year;
54+
}), 0);
55+
console.log(totalYears);
56+
4457
// 5. Sort the inventors by years lived
4558

59+
const yearsLived = inventors.sort((a, b) => (a.passed - a.year < b.passed - b.year ? 1 : -1));
60+
console.table(yearsLived);
61+
4662
// 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name
4763
// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
4864

65+
// const category = document.querySelector('.mw-category');
66+
// const links = category.querySelectorAll('a');
67+
// let res = [];
68+
// links.forEach((item) => {
69+
// // console.log(typeof item.title)
70+
// if (/de/i.test(item.title)) {
71+
// res.push(item.title);
72+
// }
73+
// });
74+
// console.log(res);
75+
// // console.log(links);
76+
4977

5078
// 7. sort Exercise
5179
// Sort the people alphabetically by last name
80+
lastNameSorted = people.sort((a, b) => {
81+
const surnameA = a.split(',');
82+
const surnameB = b.split(',');
83+
return surnameA > surnameB ? 1 : -1;
84+
});
85+
console.table(lastNameSorted);
86+
5287

5388
// 8. Reduce Exercise
5489
// Sum up the instances of each of these
5590
const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ];
5691

92+
const dataRes = data.reduce(function(obj, item) {
93+
// console.log(item);
94+
if (!obj[item]) {
95+
obj[item] = 0;
96+
}
97+
obj[item]++;
98+
return obj;
99+
100+
}, {});
101+
console.log(dataRes);
102+
103+
104+
57105
</script>
58106
</body>
59107
</html>

0 commit comments

Comments
 (0)