-
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
Update pset-iterators.js #10
base: master
Are you sure you want to change the base?
Conversation
completed
console.log('Problem 2:') | ||
|
||
// Add your code below this line | ||
const presidentsNamedJames = presidents.filter((president) => { | ||
return president.president.includes('James') | ||
}).map(function (president) { | ||
return president.president | ||
}) | ||
|
||
|
||
console.log(presidentsNamedJames) |
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.
@jct117 Great work here on this solution to look up the presidents whose name includes 'James' using the filter method.
One Suggestion
-For this example, you could remove the map method because for this example you were to return an Array of objects and the filter method without the map will give you that outcome.
Take a look at the alternate solutions here
const firstWhigPresident = presidents.find(function (president) { | ||
return president.party === "Whig" | ||
}) | ||
|
||
console.log(firstWhigPresident.president) |
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.
console.log('Problem 3:') | ||
|
||
// Add your code below this line | ||
const presidentialParties = presidents.map((party) => { | ||
return party.party | ||
}) | ||
|
||
console.log(presidentialParties) |
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.
const presidentsBetween1850and1900 = presidents.filter((president, year1) => { | ||
let officeTerm = president.took_office >= "1850" && president.left_office <= "1900" | ||
return officeTerm | ||
}).filter(function (officeTerm) { | ||
return officeTerm.president | ||
}) | ||
|
||
console.log(presidentsBetween1850and1900) |
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.
@jct117 Good job putting together this solution to find all of the presidents who served between 1850 and 1900. Currently, I see you have two filter method but for this example one filter is fine. when you run the second filter it ass a president who served outside of the years 1850 - 1900. Also since we are checking to see who served during this period of time you should replace president.left_office <= "1900"
with president.took_office <= "1900"
. This will let us know if any president took office between 1850 and 1900
Take a look at this approach here
console.log('Problem 5:') | ||
|
||
// Add your code below this line | ||
const livingPresidents = presidents.filter((president) => { | ||
let alive = president.death_year === null | ||
return alive | ||
}) | ||
|
||
|
||
console.log(livingPresidents) |
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.
console.log('Problem 6:') | ||
|
||
// Add your code below this line | ||
const firstRepublican = presidents.find((party) => { | ||
return party.party === "Republican" | ||
}) | ||
|
||
|
||
console.log(firstRepublican.president) |
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.
const shortTermPresidents = presidents.filter((president) => { | ||
let start = parseInt(president.took_office) | ||
let end = parseInt(president.left_office) | ||
|
||
return end - start < 4 | ||
}) | ||
|
||
|
||
console.log(shortTermPresidents) |
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.
completed homework