-
Notifications
You must be signed in to change notification settings - Fork 2.3k
learning foreach #177
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
Open
bwhite06
wants to merge
5
commits into
bloominstituteoftechnology:master
Choose a base branch
from
bwhite06:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
learning foreach #177
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,23 +54,60 @@ const runners = [{"id":1,"first_name":"Charmain","last_name":"Seiler","email":"c | |
| {"id":50,"first_name":"Shell","last_name":"Baine","email":"[email protected]","shirt_size":"M","company_name":"Gabtype","donation":171}]; | ||
|
|
||
| // ==== Challenge 1: Use .forEach() ==== | ||
| // The event director needs both the first and last names of each runner for their running bibs. Combine both the first and last names into a new array called fullName. | ||
| // The event director needs both the first and last names of each runner for their running bibs. Combine both the first and last names into a new array called fullName. | ||
| let fullName = []; | ||
| findrunner(); | ||
| console.log(fullName); | ||
| function findrunner(){ | ||
| runners.forEach(function(i) { | ||
| fullName.push(i.first_name+" "+i.last_name); | ||
|
|
||
|
|
||
| }); | ||
| JSON.stringify(fullName); | ||
| } | ||
|
|
||
| // ==== Challenge 2: Use .map() ==== | ||
| // The event director needs to have all the runner's first names converted to uppercase because the director BECAME DRUNK WITH POWER. Convert each first name into all caps and log the result | ||
| let allCaps = []; | ||
| console.log(allCaps); | ||
| let v = []; | ||
| allCapsMeth() | ||
| console.log(v); | ||
| function allCapsMeth(){ | ||
| runners.forEach(function(i) { | ||
| let result = i.first_name | ||
|
|
||
| allCaps.push(result); | ||
|
|
||
|
|
||
| }); | ||
| v.push(allCaps.map(x => x.toUpperCase())); | ||
| } | ||
|
|
||
|
|
||
| // ==== Challenge 3: Use .filter() ==== | ||
| // The large shirts won't be available for the event due to an ordering issue. Get a list of runners with large sized shirts so they can choose a different size. Return an array named largeShirts that contains information about the runners that have a shirt size of L and log the result | ||
| let largeShirts = []; | ||
| let largeShirts = runners.filter((shirts)=> { | ||
| return shirts.shirt_size ==="L"; | ||
| }); | ||
|
|
||
| console.log(largeShirts); | ||
|
|
||
|
|
||
|
|
||
|
|
||
| // ==== Challenge 4: Use .reduce() ==== | ||
| // The donations need to be tallied up and reported for tax purposes. Add up all the donations into a ticketPriceTotal array and log the result | ||
| let ticketPriceTotal = []; | ||
|
|
||
| let ticketPriceTotal = 0; | ||
| let result=[]; | ||
| for (var i = 0; i < runners.length; i++) { | ||
| result.push(runners[i].donation); | ||
| } | ||
| ticketPriceTotal = result.reduce( | ||
| ( accumulator, currentValue ) => accumulator + currentValue, | ||
| 0 | ||
| ); | ||
| console.log(ticketPriceTotal); | ||
|
|
||
| // ==== Challenge 5: Be Creative ==== | ||
|
|
@@ -80,4 +117,4 @@ console.log(ticketPriceTotal); | |
|
|
||
| // Problem 2 | ||
|
|
||
| // Problem 3 | ||
| // Problem 3 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <html> | ||
| <head> | ||
|
|
||
| - <title>Page Title</title> | ||
| + <script type="text/javascript" src="assignments\callbacks.js"></script> | ||
| + <script type="text/javascript" src="assignments\array-methods.js"></script> | ||
| <script type="text/javascript" src="assignments\closure.js"></script> | ||
| <script type="text/javascript" src="assignments\function-conversion.js"></script> | ||
| + <title>Page Title</title> | ||
| </head> | ||
| <body> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Try not to use
var