Skip to content

Commit 4c26708

Browse files
author
mjdude
committed
finished first 3 array challanges
1 parent d9d9634 commit 4c26708

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,33 @@
3131

3232
// Array.prototype.filter()
3333
// 1. Filter the list of inventors for those who were born in the 1500's
34+
const fifteen = inventors.filter((inventor) => {
35+
return inventor.year >= 1500 && inventor.year <= 1600;
36+
});
37+
38+
console.log('Born in 1500:');
39+
console.log(fifteen);
3440

3541
// Array.prototype.map()
3642
// 2. Give us an array of the inventors' first and last names
3743

44+
const fullNames = inventors.map((inventor) => {
45+
return `${inventor.first} ${inventor.last}`;
46+
});
47+
console.log('inventors full names:');
48+
console.log(fullNames);
49+
3850
// Array.prototype.sort()
3951
// 3. Sort the inventors by birthdate, oldest to youngest
52+
const birthdate = inventors.sort((a,b) => {
53+
const a_age = a.passed - a.year;
54+
const b_age = b.passed - b.year;
55+
56+
return b_age - a_age;
57+
})
4058

59+
console.log('Birthday oldest to youngest');
60+
console.log(birthdate);
4161
// Array.prototype.reduce()
4262
// 4. How many years did all the inventors live?
4363

0 commit comments

Comments
 (0)