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 #10

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

Conversation

jct117
Copy link

@jct117 jct117 commented Oct 4, 2019

completed homework

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

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

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

console.log(firstWhigPresident.president)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jct117 Good job here using the find method to return the first president in the whig party

Take a look at this solution here

Comment on lines 107 to +114
console.log('Problem 3:')

// Add your code below this line
const presidentialParties = presidents.map((party) => {
return party.party
})

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.

@jct117 Good job on this solution here, to use the map method to return all of the president's party.

Take a look at an alternate approach here

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

@Tech-J Tech-J Oct 14, 2019

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

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jct117 Good job on this solution using the filter method to look up the current living presidents.

Take a look at this solution here

Comment on lines 194 to +202
console.log('Problem 6:')

// Add your code below this line
const firstRepublican = presidents.find((party) => {
return party.party === "Republican"
})


console.log(firstRepublican.president)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jct117 Great Job here using the find method to return all of the presidents who belong to the Republican party.

Take a look at this solution here

Comment on lines +226 to +234
const shortTermPresidents = presidents.filter((president) => {
let start = parseInt(president.took_office)
let end = parseInt(president.left_office)

return end - start < 4
})


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.

@jct117 Great Job on this solution using the filter method to retrieve the presidents who served less than 4 years. Good Job using the parseInt method to retrieve the value of the year in a number.

Take a look at this solution 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