Repository navigation
WEB EU2 - JAYNE NORRIE - ALEX E - WEEK 3 GUIDED DAY 2 #2
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,19 +55,27 @@ const runners = [{"id":1,"first_name":"Charmain","last_name":"Seiler","email":"c | |
|
|
||
| // ==== 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. | ||
| let fullName = runners.map((name, surName) => { | ||
| return {name: runners["first_name"], surName: runners["last_name"]}; | ||
| let fullName = [];runners.forEach(function (info) { | ||
| fullName.push (`${info.first_name} ${info.last_name}`); | ||
| }); | ||
| console.log(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 = []; | ||
| runners.map(function(info) { | ||
| allCaps.push(info.first_name.toUpperCase()); | ||
| }) | ||
| console.log(allCaps); | ||
|
|
||
| // ==== 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 = []; | ||
| runners.filter(function(info) { | ||
| if (info.shirt_size === "L") | ||
| return largeShirts.push(`${info.first_name} ${info.last_name} ordered a Large shirt`); | ||
| }); | ||
| console.log(largeShirts); | ||
|
|
||
| // ==== Challenge 4: Use .reduce() ==== | ||
|
|
@@ -78,8 +86,26 @@ console.log(ticketPriceTotal); | |
| // ==== Challenge 5: Be Creative ==== | ||
| // Now that you have used .forEach(), .map(), .filter(), and .reduce(). I want you to think of potential problems you could solve given the data set and the 5k fun run theme. Try to create and then solve 3 unique problems using one or many of the array methods listed above. | ||
|
|
||
| // Problem 1 | ||
| // Problem 1 Need a party invite list for participants who donated over 200 | ||
| let partyList = []; | ||
| runners.map(function(info) { | ||
| if (info.donation > 200) | ||
| return partyList.push(`${info.first_name} ${info.last_name} should be added to the guest list`); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here it would be good practice to save |
||
| }); | ||
| console.log(partyList); | ||
|
|
||
| // Problem 2 | ||
| // Problem 2 Email list of people who ordered small shirts | ||
| let smallShirts = []; | ||
| runners.filter(function(info) { | ||
| if (info.shirt_size === "S") | ||
| return smallShirts.push(`${info.first_name} ${info.email}`); | ||
| }); | ||
| console.log(smallShirts); | ||
|
|
||
| // Problem 3 | ||
| // Problem 3 number of people from Skinix company | ||
| let companySkinix = []; | ||
| runners.map(function(info) { | ||
| if (info.company_name === "Skinix") | ||
| return companySkinix.push(` ${info.company_name}: ${info.first_name} ${info.last_name}`); | ||
| }); | ||
| console.log(companySkinix); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good stuff!! 🔥 |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,38 +8,41 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum']; | |
|
|
||
| function firstItem(arr, cb) { | ||
| // firstItem passes the first item of the given array to the callback function. | ||
| } | ||
| }*/ | ||
| // function firstItem(arr, callBack) { | ||
| // return callBack(arr); | ||
|
|
||
| // Potential Solution: | ||
|
|
||
| // Higher order function using "cb" as the call back | ||
| function firstItem(arr, cb) { | ||
| return cb(arr[0]); | ||
| function getInfo(arr, cb) { | ||
| return cb(arr); | ||
| // return cb(arr[0]); | ||
| } | ||
|
|
||
| // Function invocation | ||
| firstItem(items, function(first) { | ||
| console.log(first) | ||
| }); | ||
| function firstItem(info) { | ||
| return info[0]; | ||
| }; | ||
|
|
||
| */ | ||
| console.log(getInfo(items, firstItem)); | ||
|
|
||
|
|
||
| function getLength(arr, cb) { | ||
| function getLength(info) { | ||
| // getLength passes the length of the array into the callback. | ||
| return cb(arr.length); | ||
| return info.length; | ||
| } | ||
| getLength(items, (length) => { | ||
| console.log(length); | ||
| }) | ||
| console.log(getInfo(items, getLength)); | ||
| // getLength(items, (length) => { | ||
| // console.log(length); | ||
| // }) | ||
|
|
||
| function last(arr, cb) { | ||
| // last passes the last item of the array into the callback. | ||
| return cb(arr[arr.length - 1]); | ||
| return arr[arr.length - 1]; | ||
| } | ||
| last(items, (index) => { | ||
| console.log(index); | ||
| }) | ||
| console.log(getInfo(items, last)); | ||
|
|
||
|
|
||
| function sumNums(x, y, cb) { | ||
| // sumNums adds two numbers (x, y) and passes the result to the callback. | ||
|
|
@@ -57,22 +60,20 @@ multiplyNums(2, 3, (callBack) => { | |
| console.log(callBack); | ||
| }) | ||
|
|
||
| function contains(item, list, cb) { | ||
| // function contains(item, list, cb) { | ||
| // contains checks if an item is present inside of the given array/list. | ||
| // Pass true to the callback if it is, otherwise pass false. | ||
| } | ||
|
|
||
| // function contains (item, list, cb) { | ||
| // for (let i = 0; i < list.length, i++); | ||
| // if (item === list[i]) { | ||
| // return cb(list [i]); | ||
| // } | ||
| // } | ||
|
|
||
| function contains (item, list, cb) { | ||
| if (item === list[i]) { | ||
| return cb(list[i]); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here you have not defined what |
||
| } | ||
| } | ||
|
|
||
| // contains('Gum', items, (callBack) => { | ||
| // console.log(callBack); | ||
| // }); | ||
| contains('Gum', items, (callBack) => { | ||
| console.log(callBack); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting way of doing this. 👍 |
||
| }); | ||
|
|
||
| /* STRETCH PROBLEM */ | ||
|
|
||
|
|
||
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.
Nice interpolation 🔥