Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

AtleLohrmann
Copy link

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.

Comment on lines +46 to +50
const firstWhigPresident = presidents.find(function (president) {
return president.party === 'Whig'
})

console.log("First president from the Whig party:",firstWhigPresident.president)
Copy link

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

Comment on lines 73 to +82
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)
Copy link

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

Comment on lines 106 to +114
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)
Copy link

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

Comment on lines +137 to +145
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)


Copy link

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

Comment on lines 165 to +173
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)
Copy link

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

Comment on lines 196 to +204
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)
Copy link

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

Comment on lines 226 to +242
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)
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants