-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
completed homework #2
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,11 @@ console.log('Problem 1:') | |
|
||
// Add your code below this line | ||
|
||
// find the first president that was a member of the party named Whig | ||
const firstWhigPresident = presidents.find(selectedPresidentObj => selectedPresidentObj.party === 'Whig') | ||
// print to console | ||
console.log(firstWhigPresident.president) | ||
|
||
// Add your code above this line | ||
|
||
/** added for formatting purposes **/ | ||
|
@@ -66,6 +71,14 @@ console.log('Problem 2:') | |
|
||
// Add your code below this line | ||
|
||
// Get a list of presidents whos first name is James | ||
const presidentsNamedJames = presidents.filter(presidentObj => { | ||
// presidentObj.president.split(' ') is the president name split into an array | ||
// first name is stored at [0] index | ||
return presidentObj.president.split(' ')[0] === 'James' | ||
}) | ||
|
||
console.log(presidentsNamedJames) | ||
Comment on lines
+74
to
+81
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
// Add your code above this line | ||
|
||
/** added for formatting purposes **/ | ||
|
@@ -93,6 +106,9 @@ console.log('Problem 3:') | |
|
||
// Add your code below this line | ||
|
||
// grab all presidential party names from presidents object and print to console | ||
const presidentialParties = presidents.map(presidentObj => presidentObj.party) | ||
console.log(presidentialParties) | ||
Comment on lines
+110
to
+111
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
// Add your code above this line | ||
|
||
/** added for formatting purposes **/ | ||
|
@@ -115,6 +131,14 @@ console.log('Problem 4:') | |
|
||
// Add your code below this line | ||
|
||
// grab list of presidents that were in office between 1850 and 1900 | ||
const presidentsBetween1850and1900 = presidents.filter(presidentObj => { | ||
// presidentObj.took_office.split('-')[0] = year the president took office | ||
return (presidentObj.took_office.split('-')[0] > 1850) & (presidentObj.took_office.split('-')[0] < 1900) | ||
}) | ||
|
||
// print to console | ||
console.log(presidentsBetween1850and1900) | ||
Comment on lines
+135
to
+141
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
// Add your code above this line | ||
|
||
/** added for formatting purposes **/ | ||
|
@@ -138,6 +162,12 @@ console.log('Problem 5:') | |
|
||
// Add your code below this line | ||
|
||
// grab list of presidents that have no death year listed | ||
const livingPresidents = presidents.filter(presidentObj => presidentObj.death_year === null) | ||
|
||
// print to console | ||
console.log(livingPresidents) | ||
Comment on lines
+166
to
+169
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
// Add your code above this line | ||
|
||
/** added for formatting purposes **/ | ||
|
@@ -161,6 +191,12 @@ console.log('Problem 6:') | |
|
||
// Add your code below this line | ||
|
||
// find the first repblican president listed in the presidents Object | ||
const firstRepublican = presidents.find(presidentObj => presidentObj.party === 'Republican') | ||
|
||
// print their name to console | ||
console.log(firstRepublican.president) | ||
|
||
// Add your code above this line | ||
|
||
/** added for formatting purposes **/ | ||
|
@@ -184,6 +220,21 @@ console.log('Problem 7:') | |
|
||
// Add your code below this line | ||
|
||
// grab a list of presidents who have been in office for less than 4 years | ||
const shortTermPresidents = presidents.filter(presidentObj => { | ||
if (presidentObj.left_office === null) { | ||
// if the president never left office, calculate based off the cufrent year (2019) | ||
return (2019 - presidentObj.took_office.split('-')[0]) < 4 | ||
} else { | ||
// below line calculates the year the president took office minus | ||
// the year the president left office and retuns the object if the Result | ||
// is less than 4 | ||
return (presidentObj.left_office.split('-')[0] - presidentObj.took_office.split('-')[0]) < 4 | ||
} | ||
}) | ||
|
||
// print to console | ||
console.log(shortTermPresidents) | ||
Comment on lines
+224
to
+237
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
// Add your code above this line | ||
|
||
/** added for formatting purposes **/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sad3xoxo Great work here on this solution using the find method to return the first president of the whig party.
Take a look at this solution here