From 2aab4f9965c55ad433c7a5f9b9d02c873f5ca5c7 Mon Sep 17 00:00:00 2001 From: Frankzhac Date: Tue, 9 Apr 2019 18:39:27 -0400 Subject: [PATCH 1/3] array-methods --- assignments/array-methods.js | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/assignments/array-methods.js b/assignments/array-methods.js index f692c35c6..3d34f12e0 100644 --- a/assignments/array-methods.js +++ b/assignments/array-methods.js @@ -54,23 +54,32 @@ const runners = [{"id":1,"first_name":"Charmain","last_name":"Seiler","email":"c {"id":50,"first_name":"Shell","last_name":"Baine","email":"sbaine1d@intel.com","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. -let fullName = []; -console.log(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 = [] +runners.forEach(function(currentValue){ + fullName.push(currentValue["first_name"] + " " + currentValue["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 = []; -console.log(allCaps); +let allCaps = runners.map(function(items){ + return items.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 = []; +//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((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 = runners.reduce((donationTotal, donationAmount) => { + return donationTotal + donationAmount.donation; +}, 0); console.log(ticketPriceTotal); // ==== Challenge 5: Be Creative ==== @@ -80,4 +89,4 @@ console.log(ticketPriceTotal); // Problem 2 -// Problem 3 \ No newline at end of file +// Problem 3 From 0153009a829a67a29573d3158e2131b56a22751d Mon Sep 17 00:00:00 2001 From: Frankzhac Date: Tue, 9 Apr 2019 19:23:09 -0400 Subject: [PATCH 2/3] added closure --- assignments/closure.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/assignments/closure.js b/assignments/closure.js index 4307524fc..54824518b 100644 --- a/assignments/closure.js +++ b/assignments/closure.js @@ -1,7 +1,15 @@ // ==== Challenge 1: Write your own closure ==== // Write a simple closure of your own creation. Keep it simple! +function daGod() { + const king = "Elohim"; + console.log(`Hello from above! How are you ${Elohim}`) - + function planet() { + const name = "Yashua"; + console.log(`Hello from above! Have you prayed to ${king}`) + } + planet(); +} /* STRETCH PROBLEMS, Do not attempt until you have completed all previous tasks for today's project files */ From 340a947b150595399e2631f871b9f237196d4514 Mon Sep 17 00:00:00 2001 From: Frankzhac Date: Tue, 9 Apr 2019 20:08:16 -0400 Subject: [PATCH 3/3] updated closure --- assignments/closure.js | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/assignments/closure.js b/assignments/closure.js index 54824518b..80c3ff57e 100644 --- a/assignments/closure.js +++ b/assignments/closure.js @@ -1,8 +1,18 @@ // ==== Challenge 1: Write your own closure ==== // Write a simple closure of your own creation. Keep it simple! +function ditBonjour() { + const name = "Elohim"; + function greet() { + console.log("Bonjour " + name) + } + greet(); + } +console.log(ditBonjour()); + +// Another method to write closure function daGod() { const king = "Elohim"; - console.log(`Hello from above! How are you ${Elohim}`) + console.log(`Hello from Earth! How are you ${Elohim}`) function planet() { const name = "Yashua"; @@ -10,20 +20,26 @@ function daGod() { } planet(); } +console.log(daGod()); /* STRETCH PROBLEMS, Do not attempt until you have completed all previous tasks for today's project files */ // ==== Challenge 2: Create a counter function ==== +// const counter = () => { +// // Return a function that when invoked increments and returns a counter variable. +// }; const counter = () => { - // Return a function that when invoked increments and returns a counter variable. -}; -// Example usage: const newCounter = counter(); -// newCounter(); // 1 -// newCounter(); // 2 + let count = 0; -// ==== Challenge 3: Create a counter function with an object that can increment and decrement ==== -const counterFactory = () => { - // Return an object that has two methods called `increment` and `decrement`. - // `increment` should increment a counter variable in closure scope and return it. - // `decrement` should decrement the counter variable and return it. -}; + return () => (++count); + }; +// // Example usage: const newCounter = counter(); +// // newCounter(); // 1 +// // newCounter(); // 2 +// +// // ==== Challenge 3: Create a counter function with an object that can increment and decrement ==== +// const counterFactory = () => { +// // Return an object that has two methods called `increment` and `decrement`. +// // `increment` should increment a counter variable in closure scope and return it. +// // `decrement` should decrement the counter variable and return it. +// };