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

completed homework #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions pset-iterators.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ console.log('Problem 1:')

// Add your code below this line

// find the first president that was a member of the party named Whig
const firstWhigPresident = presidents.find(selectedPresidentObj => selectedPresidentObj.party === 'Whig')
// print to console
console.log(firstWhigPresident.president)

Comment on lines +46 to +50
Copy link

Choose a reason for hiding this comment

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

@sad3xoxo Great work here on this solution using the find method to return the first president of the whig party.

Take a look at this solution here

// Add your code above this line

/** added for formatting purposes **/
Expand All @@ -66,6 +71,14 @@ console.log('Problem 2:')

// Add your code below this line

// Get a list of presidents whos first name is James
const presidentsNamedJames = presidents.filter(presidentObj => {
// presidentObj.president.split(' ') is the president name split into an array
// first name is stored at [0] index
return presidentObj.president.split(' ')[0] === 'James'
})

console.log(presidentsNamedJames)
Comment on lines +74 to +81
Copy link

Choose a reason for hiding this comment

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

@sad3xoxo Great work here using the filter method, splitting each president's name to and returning the first name that starts with James.

Take a look at this approach here

// Add your code above this line

/** added for formatting purposes **/
Expand Down Expand Up @@ -93,6 +106,9 @@ console.log('Problem 3:')

// Add your code below this line

// grab all presidential party names from presidents object and print to console
const presidentialParties = presidents.map(presidentObj => presidentObj.party)
console.log(presidentialParties)
Comment on lines +110 to +111
Copy link

@Tech-J Tech-J Oct 13, 2019

Choose a reason for hiding this comment

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

@sad3xoxo Good Job here using the map function to return only the president's party names.

Take a look at this approach here

// Add your code above this line

/** added for formatting purposes **/
Expand All @@ -115,6 +131,14 @@ console.log('Problem 4:')

// Add your code below this line

// grab list of presidents that were in office between 1850 and 1900
const presidentsBetween1850and1900 = presidents.filter(presidentObj => {
// presidentObj.took_office.split('-')[0] = year the president took office
return (presidentObj.took_office.split('-')[0] > 1850) & (presidentObj.took_office.split('-')[0] < 1900)
})

// print to console
console.log(presidentsBetween1850and1900)
Comment on lines +135 to +141
Copy link

Choose a reason for hiding this comment

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

@sad3xoxo Good Job here using the filter method on this solution and returning the presidents between 1850 and 1900. Good work splitting the took_office and returning the value if it is greater than 1850 & less than 1900.

Take a loop at this approach here

// Add your code above this line

/** added for formatting purposes **/
Expand All @@ -138,6 +162,12 @@ console.log('Problem 5:')

// Add your code below this line

// grab list of presidents that have no death year listed
const livingPresidents = presidents.filter(presidentObj => presidentObj.death_year === null)

// print to console
console.log(livingPresidents)
Comment on lines +166 to +169
Copy link

Choose a reason for hiding this comment

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

@sad3xoxo Good job here using the filter method to find all the president's whose death year equal null.

Take a look at this approach here


// Add your code above this line

/** added for formatting purposes **/
Expand All @@ -161,6 +191,12 @@ console.log('Problem 6:')

// Add your code below this line

// find the first repblican president listed in the presidents Object
const firstRepublican = presidents.find(presidentObj => presidentObj.party === 'Republican')

// print their name to console
console.log(firstRepublican.president)

// Add your code above this line

/** added for formatting purposes **/
Expand All @@ -184,6 +220,21 @@ console.log('Problem 7:')

// Add your code below this line

// grab a list of presidents who have been in office for less than 4 years
const shortTermPresidents = presidents.filter(presidentObj => {
if (presidentObj.left_office === null) {
// if the president never left office, calculate based off the cufrent year (2019)
return (2019 - presidentObj.took_office.split('-')[0]) < 4
} else {
// below line calculates the year the president took office minus
// the year the president left office and retuns the object if the Result
// is less than 4
return (presidentObj.left_office.split('-')[0] - presidentObj.took_office.split('-')[0]) < 4
}
})

// print to console
console.log(shortTermPresidents)
Comment on lines +224 to +237
Copy link

Choose a reason for hiding this comment

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

@sad3xoxo Good work here on this problem using the filter method. Good job utilizing the conditional to determine the outcomes for the current president and past presidents

Take a look at this approach here

// Add your code above this line

/** added for formatting purposes **/
Expand Down