Skip to content

Commit 91045aa

Browse files
committed
finished task wesbos#4
1 parent 79dda9e commit 91045aa

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

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

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,32 +35,61 @@
3535
'Berne, Eric','Berra, Yogi','Berry, Wendell','Bevan, Aneurin','Ben-Gurion, David','Bevel, Ken','Biden, Joseph','Bennington, Chester','Bierce, Ambrose',
3636
'Billings, Josh','Birrell, Augustine','Blair, Tony','Beecher, Henry','Biondo, Frank'
3737
];
38-
38+
3939
// Array.prototype.filter()
4040
// 1. Filter the list of inventors for those who were born in the 1500's
41+
constfifteen=inventors.filter(inventor=>inventor.year>=1500&&inventor.year<1600);
42+
console.table(fifteen);
4143

4244
// Array.prototype.map()
4345
// 2. Give us an array of the inventors first and last names
46+
constfullNames=inventors.map(inventor=>inventor.first+' '+inventor.last);
47+
console.table(fullNames);
4448

4549
// Array.prototype.sort()
4650
// 3. Sort the inventors by birthdate, oldest to youngest
51+
constbirthdates=inventors.sort((a,b)=>(a.year>b.year ? 1 : -1));
52+
console.table(birthdates);
4753

4854
// Array.prototype.reduce()
4955
// 4. How many years did all the inventors live all together?
56+
consttotalYears=inventors.reduce((total,inventor)=>{
57+
returntotal+(inventor.passed-inventor.year);
58+
},0)
59+
console.log(totalYears);
5060

5161
// 5. Sort the inventors by years lived
62+
constsortByLife=inventors.sort((a,b)=>((a.passed-a.year)<(b.passed-b.year) ? 1 : -1));
63+
console.table(sortByLife);
5264

5365
// 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name
5466
// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
55-
67+
// const category = document.querySelector('.mw-category');
68+
// const links = [...category.querySelectorAll('a')];
69+
// const de = links
70+
// .map(link => link.textContent)
71+
// .filter(streetName => streetName.includes('de'));
5672

5773
// 7. sort Exercise
5874
// Sort the people alphabetically by last name
75+
constsortLastname=people.sort((lastOne,nextOne)=>{
76+
const[aLast,aFirst]=lastOne.split(', ');
77+
const[bLast,bFirst]=nextOne.split(', ');
78+
returnaLast>bLast ? 1 : -1;
79+
});
80+
console.table(sortLastname);
5981

6082
// 8. Reduce Exercise
6183
// Sum up the instances of each of these
6284
constdata=['car','car','truck','truck','bike','walk','car','van','bike','walk','car','van','car','truck'];
63-
85+
consttransportation=data.reduce((obj,item)=>{
86+
if(!obj[item]){
87+
obj[item]=0;
88+
}
89+
obj[item]++;
90+
returnobj;
91+
},{});
92+
console.log(transportation)
6493
</script>
6594
</body>
6695
</html>

0 commit comments

Comments
(0)