Skip to content

Commit 5add70d

Browse files
author
Miguel Bautista
committed
cardio done
1 parent 51a7c04 commit 5add70d

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

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

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,29 +32,63 @@
3232

3333
// Array.prototype.filter()
3434
// 1. Filter the list of inventors for those who were born in the 1500's
35-
35+
let fifteen = inventors.filter(inventor =>(inventor.year >= 1500 && inventor.year < 1600));
36+
console.table(fifteen);
3637
// Array.prototype.map()
3738
// 2. Give us an array of the inventors' first and last names
39+
let firstNameLastName = inventors.map(inventor => inventor.first +" "+ inventor.last);
40+
console.log(firstNameLastName);
3841

3942
// Array.prototype.sort()
4043
// 3. Sort the inventors by birthdate, oldest to youngest
44+
let birthdays = inventors.sort((a,b)=>(a.year > b.year) ? 1 : -1);
45+
console.table(birthdays);
4146

4247
// Array.prototype.reduce()
4348
// 4. How many years did all the inventors live?
49+
let totalYears = inventors.reduce((total, inventor)=> {
50+
return total + (inventor.passed - inventor.year);
51+
}, 0); // note the zero at the end
52+
console.log(totalYears);
53+
4454

4555
// 5. Sort the inventors by years lived
4656

57+
let oldest = inventors.sort((a,b) => {
58+
let lastPerson = a.passed - a.year;
59+
let nextPerson = b.passed - b.year;
60+
return (lastPerson > nextPerson) ? 1 : -1;
61+
});
62+
63+
console.table(oldest);
64+
4765
// 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name
4866
// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
4967

5068

5169
// 7. sort Exercise
5270
// Sort the people alphabetically by last name
71+
let alphabetically = people.sort((lastOne, nextOne)=>{
72+
let [aLast, aFirst] = lastOne.split(', ');
73+
let [bLast, bFirst] = nextOne.split(', ');
74+
return aLast > bLast ? 1 : -1;
75+
});
76+
console.log(alphabetically);
5377

5478
// 8. Reduce Exercise
5579
// Sum up the instances of each of these
5680
const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ];
5781

82+
83+
let transportation = data.reduce((obj, item)=>{
84+
if (!obj[item]){
85+
obj[item] = 0;
86+
}
87+
obj[item]++;
88+
return obj;
89+
}, {});
90+
console.log(transportation);
91+
5892
</script>
5993
</body>
6094
</html>

0 commit comments

Comments
 (0)