-
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 #4
base: master
Are you sure you want to change the base?
Conversation
const firstWhigPresident = presidents.find(function (president) { | ||
return president.party === 'Whig' | ||
}) | ||
|
||
console.log("First president from the Whig party:",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.
@AtleLohrmann Good Job here using the find method to return the first president from the Whig party.
Take a look at this solution here
console.log('Problem 2:') | ||
|
||
// Add your code below this line | ||
const presidentsNamedJames = presidents.filter(function (president) { | ||
name=president.president.split(" ") | ||
return name[0] === 'James' | ||
}) | ||
|
||
|
||
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.
@AtleLohrmann Good job using the filter method to return all of the presidents whose name is James. Good job using the split method to return an array with both first and last names separated.
Take a look at this solution here
console.log('Problem 3:') | ||
|
||
// Add your code below this line | ||
const presidentialParties = presidents.map(function (president) { | ||
return president.party | ||
}) | ||
|
||
console.log("All the parties the presidents belonged to:") | ||
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.
@AtleLohrmann Good Job here using the map method to return on the president party name.
Take a look at this solution here
const presidentsBetween1850and1900 = presidents.filter(function (president) { | ||
started=president.took_office.split(" ") | ||
return parseInt(started) >= 1850 && parseInt(started) < 1900 | ||
}) | ||
|
||
console.log("Presidents who took office between 1850 and 1900:") | ||
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.
@AtleLohrmann Great work here using the filter method to return all the president who served between 1850 and 1900. Good Job using the parseInt to change the values from a string to a number.
Take a look at this solution here
console.log('Problem 5:') | ||
|
||
// Add your code below this line | ||
const livingPresidents = presidents.filter(function (president) { | ||
return president.death_year === null | ||
}) | ||
|
||
console.log("Presidents who are still 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.
@AtleLohrmann Good Job here with this solution using the filter method to return the current living president's
Take a look at this approach here
console.log('Problem 6:') | ||
|
||
// Add your code below this line | ||
const firstRepublican = presidents.find(function (president) { | ||
return president.party === 'Republican' | ||
}) | ||
|
||
console.log("First president from the Republican party:",firstRepublican.president) | ||
console.log("Full details:",firstRepublican) |
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.
@AtleLohrmann Great work here to use the find method to return only the first president in the republican party
Take a look at this solution here
console.log('Problem 7:') | ||
|
||
// Add your code below this line | ||
const shortTermPresidents = presidents.filter(function (president) { | ||
// today's president is special case but has not yet left office | ||
if (president.left_office === null) { | ||
president.left_office="2019-09-30" | ||
} | ||
let started=president.took_office.split("-") | ||
let ended=president.left_office.split("-") | ||
// including number of months in the calculation (did not include days.....) | ||
let duration=parseInt(ended[0])-parseInt(started[0]) + (parseInt(ended[1])-parseInt(started[1]))/12 | ||
return duration < 4 | ||
}) | ||
|
||
console.log("Presidents who lasted less than four years in office (also individuals just short of 4 months):") | ||
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.
@AtleLohrmann Good Job here with this solution to return the presidents who served for less than 4 years.
I have some suggestions here
- For presidents who left office equals null instead of setting a current date you can just return false so you can lease those presidents of the list.
- For this example, nice work with the month calculation but for this example only looking up the year would've been sufficient.
Take a look at this approach here
The program is working -- no real questions but fascinated by how attributes of objects generated by filter (vs. find) cannot easily be accessed using the dot notation. Took some frustration before this became clear. Anyway, it helps to practice.