From 9620c29acc8e7aa165b00b3e5a3b11d5faab95c7 Mon Sep 17 00:00:00 2001 From: Bryan Szendel Date: Tue, 11 Jun 2019 13:53:46 -0600 Subject: [PATCH 1/9] Callbacks 1 and 2 complete --- README.md | 12 ++++++------ assignments/callbacks.js | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 6288977c2..d5e561298 100644 --- a/README.md +++ b/README.md @@ -7,12 +7,12 @@ With some basic JavaScript principles in hand, we can now expand our skills out **Follow these steps to set up and work on your project:** -* [ ] Create a forked copy of this project. -* [ ] Add your project manager as collaborator on Github. -* [ ] Clone your OWN version of the repository (Not Lambda's by mistake!). -* [ ] Create a new branch: git checkout -b ``. -* [ ] Implement the project on your newly created `` branch, committing changes regularly. -* [ ] Push commits: git push origin ``. +* [X] Create a forked copy of this project. +* [X] Add your project manager as collaborator on Github. +* [X] Clone your OWN version of the repository (Not Lambda's by mistake!). +* [X] Create a new branch: git checkout -b ``. +* [X] Implement the project on your newly created `` branch, committing changes regularly. +* [X] Push commits: git push origin ``. **Follow these steps for completing your project.** diff --git a/assignments/callbacks.js b/assignments/callbacks.js index c1c013800..d836e67da 100644 --- a/assignments/callbacks.js +++ b/assignments/callbacks.js @@ -25,22 +25,48 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum']; */ +// CALLBACK 1 + function getLength(arr, cb) { // getLength passes the length of the array into the callback. + return cb(arr.length) } +getLength(items, function(length) { + console.log('length: ', length) +}); + + +// CALLBACK 2 + function last(arr, cb) { // last passes the last item of the array into the callback. + let lastIndex = arr.length - 1; + // console.log(lastIndex); + return cb(arr[lastIndex]); } +last(items, function(lastItem) { + console.log('last item: ', lastItem) +}); + + +// CALLBACK 3 + function sumNums(x, y, cb) { // sumNums adds two numbers (x, y) and passes the result to the callback. } + +// CALLBACK 4 + function multiplyNums(x, y, cb) { // multiplyNums multiplies two numbers and passes the result to the callback. } + +// CALLBACK 5 + 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. From 9148faec6207e767bc0709b651c7d6a7ed5a76ad Mon Sep 17 00:00:00 2001 From: Bryan Szendel Date: Tue, 11 Jun 2019 14:04:12 -0600 Subject: [PATCH 2/9] Callbacks 3 and 4 complete --- assignments/callbacks.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/assignments/callbacks.js b/assignments/callbacks.js index d836e67da..147a480b1 100644 --- a/assignments/callbacks.js +++ b/assignments/callbacks.js @@ -33,7 +33,7 @@ function getLength(arr, cb) { } getLength(items, function(length) { - console.log('length: ', length) + console.log('Length: ', length) }); @@ -47,7 +47,7 @@ function last(arr, cb) { } last(items, function(lastItem) { - console.log('last item: ', lastItem) + console.log('Last Item: ', lastItem) }); @@ -55,15 +55,27 @@ last(items, function(lastItem) { function sumNums(x, y, cb) { // sumNums adds two numbers (x, y) and passes the result to the callback. + let addNumbers = x + y; + return cb(addNumbers); } +sumNums(7, 8, function(additions) { + console.log('Sum of Numbers: ', additions); +}); + // CALLBACK 4 function multiplyNums(x, y, cb) { // multiplyNums multiplies two numbers and passes the result to the callback. + let multiNumber = x * y; + return cb(multiNumber); } +multiplyNums(4, 8, function(multis) { + console.log('Multiply Numbers: ', multis); +}); + // CALLBACK 5 From cec550c4b8e53035cc29fb60612ae8cede849c89 Mon Sep 17 00:00:00 2001 From: Bryan Szendel Date: Tue, 11 Jun 2019 14:29:29 -0600 Subject: [PATCH 3/9] Callback 5 complete --- assignments/callbacks.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/assignments/callbacks.js b/assignments/callbacks.js index 147a480b1..0434453df 100644 --- a/assignments/callbacks.js +++ b/assignments/callbacks.js @@ -82,7 +82,21 @@ multiplyNums(4, 8, function(multis) { 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. -} + let x = list.includes(item); + if (cb(x)) { + return true; + } else false; +}; + +var a = 'Pencil'; +contains(a, items, function(containsIt) { + console.log(`Does it contain '${a}'? : `, containsIt); +}); + +var b = 'parks'; +contains(b, items, function(containsIt) { + console.log(`Does it contain '${b}'? : `, containsIt); +}); /* STRETCH PROBLEM */ From e242b650cc508a1691aeefaa7e03f8b0309cc9fe Mon Sep 17 00:00:00 2001 From: Bryan Szendel Date: Tue, 11 Jun 2019 16:01:09 -0600 Subject: [PATCH 4/9] Arrays Challenge 1 complete --- README.md | 10 +++++----- assignments/array-methods.js | 5 ++++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index d5e561298..a3abd567c 100644 --- a/README.md +++ b/README.md @@ -16,17 +16,17 @@ With some basic JavaScript principles in hand, we can now expand our skills out **Follow these steps for completing your project.** -* [ ] Submit a Pull-Request to merge Branch into master (student's Repo). **Please don't merge your own pull request** -* [ ] Add your project manager as a reviewer on the pull-request -* [ ] Your project manager will count the project as complete by merging the branch back into master. +* [X] Submit a Pull-Request to merge Branch into master (student's Repo). **Please don't merge your own pull request** +* [X] Add your project manager as a reviewer on the pull-request +* [X] Your project manager will count the project as complete by merging the branch back into master. ## Task 2: Higher Order Functions and Callbacks This task focuses on getting practice with higher order functions and callback functions by giving you an array of values and instructions on what to do with that array. -* [ ] Review the contents of the [callbacks.js](assignments/callbacks.js) file. Notice you are given an array at the top of the page. Use that array to aid you with your functions. +* [X] Review the contents of the [callbacks.js](assignments/callbacks.js) file. Notice you are given an array at the top of the page. Use that array to aid you with your functions. -* [ ] Complete the problems provided to you but skip over stretch problems until you are complete with every other JS file first. +* [X] Complete the problems provided to you but skip over stretch problems until you are complete with every other JS file first. ## Task 3: Array Methods diff --git a/assignments/array-methods.js b/assignments/array-methods.js index f692c35c6..6d3d5b3f4 100644 --- a/assignments/array-methods.js +++ b/assignments/array-methods.js @@ -56,7 +56,10 @@ 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 = []; -console.log(fullName); + +runners.forEach(item => fullName.push(item['first_name'] + ' ' + item['last_name'])); + +console.log('full names here: ', 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 From 8c0d22d44edaadd71ee523c5c738de9330efecd0 Mon Sep 17 00:00:00 2001 From: Bryan Szendel Date: Tue, 11 Jun 2019 16:09:44 -0600 Subject: [PATCH 5/9] Arrays Challenge 2 complete --- assignments/array-methods.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/assignments/array-methods.js b/assignments/array-methods.js index 6d3d5b3f4..655be2392 100644 --- a/assignments/array-methods.js +++ b/assignments/array-methods.js @@ -61,9 +61,13 @@ runners.forEach(item => fullName.push(item['first_name'] + ' ' + item['last_name console.log('full names here: ', fullName); +// It looks like .forEach() and .push() need to be used together if they are going to add the values into a new array + // ==== 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 = []; + +allCaps = runners.map(item => item['first_name'].toUpperCase()); console.log(allCaps); // ==== Challenge 3: Use .filter() ==== From ca83d1079d1955793c735915c189b27e0b29e1c0 Mon Sep 17 00:00:00 2001 From: Bryan Szendel Date: Tue, 11 Jun 2019 16:21:56 -0600 Subject: [PATCH 6/9] Arrays Challenge 3 complete --- assignments/array-methods.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/assignments/array-methods.js b/assignments/array-methods.js index 655be2392..1bddb97a0 100644 --- a/assignments/array-methods.js +++ b/assignments/array-methods.js @@ -59,7 +59,7 @@ let fullName = []; runners.forEach(item => fullName.push(item['first_name'] + ' ' + item['last_name'])); -console.log('full names here: ', fullName); +console.log('Full Names here: ', fullName); // It looks like .forEach() and .push() need to be used together if they are going to add the values into a new array @@ -68,12 +68,19 @@ console.log('full names here: ', fullName); let allCaps = []; allCaps = runners.map(item => item['first_name'].toUpperCase()); -console.log(allCaps); +console.log('First Names in All CAPS: ', allCaps); + +// .map() includes the .push() within itself to add elements back into the allCaps array // ==== 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 = []; -console.log(largeShirts); + +largeShirts = runners.filter((item) => { + return item['shirt_size'] === 'L'; +}); + +console.log('These have Large shirts: ', 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 From 3c59053052e33c5f449fd0592fb14ef6dcfe4d2f Mon Sep 17 00:00:00 2001 From: Bryan Szendel Date: Tue, 11 Jun 2019 16:37:00 -0600 Subject: [PATCH 7/9] Closure completed --- README.md | 4 ++-- assignments/array-methods.js | 7 ++++++- assignments/closure.js | 5 +++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a3abd567c..cd8c943c1 100644 --- a/README.md +++ b/README.md @@ -32,9 +32,9 @@ This task focuses on getting practice with higher order functions and callback f Use `.forEach()`, `.map()`, `.filter()`, and `.reduce()` to loop over an array with 50 objects in it. The [array-methods.js](assignments/array-methods.js) file contains several challenges built around a fundraising 5K fun run event. -* [ ] Review the contents of the [array-methods.js](assignments/array-methods.js) file. +* [X] Review the contents of the [array-methods.js](assignments/array-methods.js) file. -* [ ] Complete the problems provided to you but skip over stretch problems until you are complete with every other JS file first. +* [X] Complete the problems provided to you but skip over stretch problems until you are complete with every other JS file first. * [ ] Notice the last three problems are up to you to create and solve. This is an awesome opportunity for you to push your critical thinking about array methods, have fun with it. diff --git a/assignments/array-methods.js b/assignments/array-methods.js index 1bddb97a0..b8892667a 100644 --- a/assignments/array-methods.js +++ b/assignments/array-methods.js @@ -85,7 +85,12 @@ console.log('These have Large shirts: ', 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 = []; -console.log(ticketPriceTotal); + +ticketPriceTotal = runners.reduce((total, item) => { + return total += item['donation']; +}, 0); + +console.log('Total Ticket Donations: $', 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. diff --git a/assignments/closure.js b/assignments/closure.js index 4307524fc..343251b52 100644 --- a/assignments/closure.js +++ b/assignments/closure.js @@ -1,6 +1,11 @@ // ==== Challenge 1: Write your own closure ==== // Write a simple closure of your own creation. Keep it simple! +const closure = 'I am closure'; +function getClosure() { + return closure; +} +console.log('This is my function getting closure: ', getClosure()); /* STRETCH PROBLEMS, Do not attempt until you have completed all previous tasks for today's project files */ From 378cd1b7ebd3b20cc04fa6165041e82b37fdecd2 Mon Sep 17 00:00:00 2001 From: Bryan Szendel Date: Tue, 11 Jun 2019 17:12:54 -0600 Subject: [PATCH 8/9] WIP: working on last 2 problems in array-methods.js --- assignments/array-methods.js | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/assignments/array-methods.js b/assignments/array-methods.js index b8892667a..aa87e41ae 100644 --- a/assignments/array-methods.js +++ b/assignments/array-methods.js @@ -95,8 +95,38 @@ console.log('Total Ticket Donations: $', 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 - Which individuals donated over $250? -// Problem 2 +let bigGivers = []; -// Problem 3 \ No newline at end of file +bigGivers = runners.filter((item) => { + return item['donation'] > 250; +}); + +console.log('We got some big givers over here: ', bigGivers); + + +// Problem 2 - Which company had the most participants? + +let activeCompany = ''; + +activeCompany = runners.filter((item) => { + return item['company']; +}); + +console.log(activeCompany); + + +// Problem 3 - Who was the highest donor? + +let highestDonor = []; +let donations = []; + +donations = runners.map(item => item['donation']); +console.log(donations); + +highestDonor = runners.filter((item) => { + donations = Math.max(item['donation']); +}); + +console.log('Highest Donor: ', highestDonor); \ No newline at end of file From 26c13fba1856fece4464f60cfae5be4c55386583 Mon Sep 17 00:00:00 2001 From: Bryan Szendel Date: Tue, 11 Jun 2019 23:06:12 -0600 Subject: [PATCH 9/9] MVP COMPLETE technically, but array-methods problems not solved --- README.md | 4 ++-- assignments/array-methods.js | 26 +++++++++++++------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index cd8c943c1..d5c0b202f 100644 --- a/README.md +++ b/README.md @@ -44,8 +44,8 @@ We have learned that closures allow us to access values in scope that have alrea **Hint: Utilize debugger statements in your code in combination with your developer tools to easily identify closure values.** -* [ ] Review the contents of the [closure.js](assignments/closure.js) file. -* [ ] Complete the problems provided to you but skip over stretch problems until you are complete with every other JS file first. +* [X] Review the contents of the [closure.js](assignments/closure.js) file. +* [X] Complete the problems provided to you but skip over stretch problems until you are complete with every other JS file first. ## Stretch Goals diff --git a/assignments/array-methods.js b/assignments/array-methods.js index aa87e41ae..75527fe09 100644 --- a/assignments/array-methods.js +++ b/assignments/array-methods.js @@ -108,25 +108,25 @@ console.log('We got some big givers over here: ', bigGivers); // Problem 2 - Which company had the most participants? -let activeCompany = ''; +let activeCompany = []; -activeCompany = runners.filter((item) => { - return item['company']; -}); +activeCompany = runners.forEach(item => activeCompany.push(item['company'])); -console.log(activeCompany); +// activeCompany = runners.filter((item) => { +// return item['company']; +// }); +console.log('Most Active Company', activeCompany); -// Problem 3 - Who was the highest donor? -let highestDonor = []; -let donations = []; +// Problem 3 - Show me emails of everyone with a Large T-shirt? -donations = runners.map(item => item['donation']); -console.log(donations); +let emails = []; -highestDonor = runners.filter((item) => { - donations = Math.max(item['donation']); +emails = runners.filter((item) => { + return item['shirt_size'] === 'L'; }); -console.log('Highest Donor: ', highestDonor); \ No newline at end of file +console.log('These are Large Emails: ', emails); + +// I can't get just the emails to show... \ No newline at end of file