-
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
final commit Andre Torres #7
base: master
Are you sure you want to change the base?
Conversation
console.log('Problem 4:') | ||
|
||
// Add your code below this line | ||
const presidentsBetween1850and1900 = president18501900.filter(function(president){ | ||
return president.took_office | ||
return president.left_office | ||
}) | ||
|
||
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.
@chicomangusta Good attempt at this solution. One suggestion because you are using the filter and the variable president18501900
this will return an error since president18501900
variable is undefined.
You can replace president18501900
with presidents
Take a look at this alternate approach here
const presidentialParties = presParties.filter(function(presParty){ | ||
return presParty.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.
@chicomangusta Good job here on this assignment. I see you're using the filter method to return the president party.
- currently, you are using
presParties
to run a filter on but the variable presParties is undefined so that would throw an error. if you change thepresParties
topresidents
your solution should work. - Also, the
map
method would've been a good option for this use case as map would've returned all of the parties for you in a new array.
Take a look at this approach here
const presidentsNamedJames = presidents.find(funsction (president){ | ||
return president.president.split("")[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.
@chicomangusta Good start to this assignment here. I have a few suggestions for you
-make sure you correct the spelling for the keyword function
- For this example, instead of using
find
that will return only the first president with the nameJames
you can use thefilter
method. - Also for the president split currently when you don't include a space in your split method, ex.
president.president.split("")[0]
it will split every single letter in the string. you would want to add a spacepresident.president.split(" ")[0]
.
Take a look at this solution here
const firstWhigPresident = presidents.find(function (president) { | ||
return president.party === "Whig" | ||
}) | ||
|
||
console.log(firstWhigPresident.party) | ||
|
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.
@chicomangusta Good job here using the find method to return the first president who belongs to the Whig
party. One suggestion when you console.log(firstWhigPresident.party)
you can leave off the .party
and just console.log(firstWhigPresident)
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.left_office === 'null' | ||
}) | ||
|
||
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.
@chicomangusta Good job on this solution here using the filter method to return all of the presidents who are currently living.
Take a look at this approach here
console.log('Problem 7:') | ||
|
||
// Add your code below this line | ||
|
||
const shortTermPresidents = presidents.filter(function(president){ | ||
return president.took_office | ||
return president.left_office | ||
}) | ||
console.log(shortTermPresidents) | ||
console.log(left_office -= took_office) |
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.
@chicomangusta Good attempt here at this solution to use this filter method to return the presidents who served for less than 4 years. You needed to do a little more inside your filter method. The solution below will help give you some further insight.
Take a look at this alternate solution here
console.log('Problem 6:') | ||
|
||
// Add your code below this line | ||
console.log(presidentsParties [0]) | ||
const firstRepublican = presidentsParties.find(function(presidentParty){ | ||
return presidentParty.party === 'Republican' | ||
}) | ||
|
||
console.log(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.
@chicomangusta Good job here reusing the variable presidentsParties
to return the first occurrence of the republican party.
Take a look at this solution here
No description provided.