From 60c5a744d4312f0e4c8249b05787d04d08c31af9 Mon Sep 17 00:00:00 2001 From: Ben Urena Date: Fri, 4 Oct 2019 22:03:51 -0500 Subject: [PATCH 1/3] Lost file... changed readme --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 143243273..555be353e 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 team lead 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 team lead 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.** From a7ebbffe4b4bae57ee90f954c511fd1e01588d28 Mon Sep 17 00:00:00 2001 From: Ben Urena Date: Mon, 7 Oct 2019 20:03:29 -0500 Subject: [PATCH 2/3] Finished MVP --- README.md | 12 ++++++------ assignments/array-methods.js | 18 +++++++++++++++++- assignments/callbacks.js | 11 +++++++++++ assignments/closure.js | 4 +++- 4 files changed, 37 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 555be353e..73b1d78de 100644 --- a/README.md +++ b/README.md @@ -24,17 +24,17 @@ With some basic JavaScript principles in hand, we can now expand our skills out 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 2: Array Methods 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. @@ -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 f3862361e..2bdd438fa 100644 --- a/assignments/array-methods.js +++ b/assignments/array-methods.js @@ -58,28 +58,44 @@ const runners = [ // ==== 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 and populate a new array called `fullNames`. This array will contain just strings. let fullNames = []; +runners.forEach(arr => fullNames.push(`${arr.first_name} ${arr.last_name}`)); console.log(fullNames); // ==== Challenge 2: Use .map() ==== // The event director needs to have all the runners' first names in uppercase because the director BECAME DRUNK WITH POWER. Populate an array called `firstNamesAllCaps`. This array will contain just strings. let firstNamesAllCaps = []; +runners.map(arr => firstNamesAllCaps.push(arr.first_name.toUpperCase())); console.log(firstNamesAllCaps); // ==== Challenge 3: Use .filter() ==== // The large shirts won't be available for the event due to an ordering issue. We need a filtered version of the runners array, containing only those runners with large sized shirts so they can choose a different size. This will be an array of objects. let runnersLargeSizeShirt = []; +runnersLargeSizeShirt = runners.filter(lSize => lSize.shirt_size === "L"); console.log(runnersLargeSizeShirt); // ==== Challenge 4: Use .reduce() ==== // The donations need to be tallied up and reported for tax purposes. Add up all the donations and save the total into a ticketPriceTotal variable. let ticketPriceTotal = 0; +ticketPriceTotal = runners.reduce((ticketPriceTotal,runner) => ticketPriceTotal += runner.donation, 0) 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 +//List all emails for marketing reaons. +let allEmails = [] +runners.forEach(runner => allEmails.push(`${runner.email}`)); +console.log(allEmails); // Problem 2 +//List all donors over 280. +let highDonors = [] +highDonors = runners.filter(amount => amount.donation >280); +console.log(highDonors); -// Problem 3 \ No newline at end of file +// Problem 3 +//People from Skinix company get special treatment at the foodcourt, list people fron this company +let teams = [] +teams = runners.filter(company => company.company_name === "Skinix"); +console.log(teams); \ No newline at end of file diff --git a/assignments/callbacks.js b/assignments/callbacks.js index cb72e70c9..a90efdc74 100644 --- a/assignments/callbacks.js +++ b/assignments/callbacks.js @@ -41,24 +41,35 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum']; function getLength(arr, cb) { // getLength passes the length of the array into the callback. + return cb(arr.length); } +getLength(items, console.log); function last(arr, cb) { // last passes the last item of the array into the callback. + return cb(arr[arr.length-1]); } +last(items, console.log); function sumNums(x, y, cb) { // sumNums adds two numbers (x, y) and passes the result to the callback. + return cb(x + y); } +sumNums(3, 4, console.log); function multiplyNums(x, y, cb) { // multiplyNums multiplies two numbers and passes the result to the callback. + return cb(x * y); } +multiplyNums(3, 7, console.log); 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 evalItem = list.filter(listItem => listItem === item)[0]; + return cb(evalItem === item) } +contains('yo-yo', items, console.log); /* STRETCH PROBLEM */ diff --git a/assignments/closure.js b/assignments/closure.js index 4b399c098..9de83a66d 100644 --- a/assignments/closure.js +++ b/assignments/closure.js @@ -3,7 +3,9 @@ // Keep it simple! Remember a closure is just a function // that manipulates variables defined in the outer scope. // The outer scope can be a parent function, or the top level of the script. - +let closure = 'This one right here'; +printClosure = () => closure; +console.log(printClosure()); /* STRETCH PROBLEMS, Do not attempt until you have completed all previous tasks for today's project files */ From 1011cb44f7a5df319844c18bbfee1c4fb3544e52 Mon Sep 17 00:00:00 2001 From: Ben Urena Date: Tue, 8 Oct 2019 20:33:38 -0500 Subject: [PATCH 3/3] Cleaned up code a bit --- assignments/callbacks.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/assignments/callbacks.js b/assignments/callbacks.js index a90efdc74..642c259fa 100644 --- a/assignments/callbacks.js +++ b/assignments/callbacks.js @@ -66,8 +66,8 @@ multiplyNums(3, 7, console.log); 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 evalItem = list.filter(listItem => listItem === item)[0]; - return cb(evalItem === item) + let checkItem = list.filter(specificItem => specificItem === item)[0]; + return cb(checkItem === item) } contains('yo-yo', items, console.log);