From 35203916284bc1da0d6fe82c38f6b1ab2b5d447a Mon Sep 17 00:00:00 2001 From: JJ Ashcraft Date: Tue, 22 May 2018 16:07:28 -0400 Subject: [PATCH 1/8] updated function conversion.js --- assignments/function-conversion.js | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/assignments/function-conversion.js b/assignments/function-conversion.js index 5e6a658a4..8d43ff165 100644 --- a/assignments/function-conversion.js +++ b/assignments/function-conversion.js @@ -1,15 +1,14 @@ // Take the commented ES5 syntax and convert it to ES6 arrow Syntax -// let myFunction = function () {}; +let myFunction = () => {}; -// let anotherFunction = function (param) { -// return param; -// }; +let anotherFunction = param => { + return param; +}; + +let add = (param1, param2) => param1 + param2; -// let add = function (param1, param2) { -// return param1 + param2; -// }; -// add(1,2); +add(1,2); //? let subtract = function (param1, param2) { return param1 - param2; @@ -17,7 +16,6 @@ let subtract = function (param1, param2) { subtract(1,2); //? exampleArray = [1,2,3,4]; -// const triple = exampleArray.map(function (num) { -// return num * 3; -// }); -// console.log(triple); \ No newline at end of file + +const triple = exampleArray.map(num => num * 3); +console.log(triple); \ No newline at end of file From 1b4613c5f694602cd995d980ff8954b1c54a51ff Mon Sep 17 00:00:00 2001 From: JJ Ashcraft Date: Tue, 22 May 2018 16:18:48 -0400 Subject: [PATCH 2/8] challenge 1 completed - closure --- assignments/closure.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/assignments/closure.js b/assignments/closure.js index 4037b64c9..bcf1856f4 100644 --- a/assignments/closure.js +++ b/assignments/closure.js @@ -1,11 +1,31 @@ // ==== Challenge 1: Write your own closure ==== // Write a simple closure of your own creation. Keep it simple! +function waterTemp(temp) { + let waterTemp = temp; + + function waterOrIce() { + if (waterTemp <= 32) { + return 'Ice Ice Baby'; + + } else { + return 'what is bruce lee\'s favorite drink? WATAAA!' + } + + } +return waterOrIce(); +} + +waterTemp(35); //? // ==== Challenge 2: Create a counter function ==== const counter = () => { - // Return a function that when invoked increments and returns a counter variable. }; + + + + + // Return a function that when invoked increments and returns a counter variable. // Example usage: const newCounter = counter(); // newCounter(); // 1 // newCounter(); // 2 From 51490a359dba3ad26e7f19390cc5f7f3466ad15e Mon Sep 17 00:00:00 2001 From: JJ Ashcraft Date: Tue, 22 May 2018 16:21:39 -0400 Subject: [PATCH 3/8] challenge 2 completed - closure --- assignments/closure.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/assignments/closure.js b/assignments/closure.js index bcf1856f4..8669900e0 100644 --- a/assignments/closure.js +++ b/assignments/closure.js @@ -19,10 +19,11 @@ return waterOrIce(); waterTemp(35); //? // ==== Challenge 2: Create a counter function ==== -const counter = () => { -}; - - +let counter = 0; +const newCounter = () => {return counter++}; +newCounter(); //? +newCounter(); //? +newCounter(); //? // Return a function that when invoked increments and returns a counter variable. From 783d68a1c14e1be43858980e7ddd87b4eef56dad Mon Sep 17 00:00:00 2001 From: JJ Ashcraft Date: Tue, 22 May 2018 17:26:56 -0400 Subject: [PATCH 4/8] challenge 3 completed - closures --- assignments/closure.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/assignments/closure.js b/assignments/closure.js index 8669900e0..200a8048b 100644 --- a/assignments/closure.js +++ b/assignments/closure.js @@ -34,7 +34,20 @@ newCounter(); //? // ==== Challenge 3: Create a counter function with an object that can increment and decrement ==== const counterFactory = () => { + let counter = { + 'count': 0, + 'increment': function() { + count++; + return count; + }, + 'decrement': function() { + count--; + return count; + } + } +} + counterFactory.counter.increment(); //? // 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. -}; + From 540e88c64aae150454d763f9b96b284560c9ee38 Mon Sep 17 00:00:00 2001 From: JJ Ashcraft Date: Tue, 22 May 2018 17:41:03 -0400 Subject: [PATCH 5/8] challenge 1 completed - array-methods --- assignments/array-methods.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/assignments/array-methods.js b/assignments/array-methods.js index f986e1ad8..514167567 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(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 4901e853fd13e3d308a0384f46717f5a4a2c5e18 Mon Sep 17 00:00:00 2001 From: JJ Ashcraft Date: Tue, 22 May 2018 17:45:32 -0400 Subject: [PATCH 6/8] challenge 2 completed - array-methods --- assignments/array-methods.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/assignments/array-methods.js b/assignments/array-methods.js index 514167567..c90f0dc14 100644 --- a/assignments/array-methods.js +++ b/assignments/array-methods.js @@ -57,13 +57,17 @@ const runners = [{"id":1,"first_name":"Charmain","last_name":"Seiler","email":"c // 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(item => { - fullName.push([`${item.first_name} ${item.last_name}`]); //? + fullName.push([item.first_name, item.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 = []; +fullName.map(item => { +allCaps.push(item[0].toUpperCase()); //? +}); + console.log(allCaps); // ==== Challenge 3: Use .filter() ==== From b61c524384ed0088b29cdea0d233a4e430db3237 Mon Sep 17 00:00:00 2001 From: JJ Ashcraft Date: Tue, 22 May 2018 18:19:31 -0400 Subject: [PATCH 7/8] Challenge 2 and Challenge 3 complete -Array Methods --- assignments/array-methods.js | 16 ++++++++++++++-- assignments/closure.js | 26 +++++++++++++++----------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/assignments/array-methods.js b/assignments/array-methods.js index c90f0dc14..06fc602a0 100644 --- a/assignments/array-methods.js +++ b/assignments/array-methods.js @@ -84,7 +84,19 @@ console.log(ticketPriceTotal); // 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 solve 3 unique problems using one or many of the array methods listed above. // Problem 1 - +// make email list and Write a thank you note to the company // Problem 2 +// filter top donator list - donors over +// Problem 3 +let topDonors = []; +runners.filter(runner => { + if (runner.donation > 200 ) { + topDonors.push([runner.company_name, '$' + runner.donation]); + } +}); + +console.log('We would like to thank the follow companies for their generous donations:' + '\n' + `${topDonors.company_name}${topDonors}`); //? + -// Problem 3 \ No newline at end of file +console.log(topDonors); +//reduce total donation diff --git a/assignments/closure.js b/assignments/closure.js index 200a8048b..f8af8d63d 100644 --- a/assignments/closure.js +++ b/assignments/closure.js @@ -34,20 +34,24 @@ newCounter(); //? // ==== Challenge 3: Create a counter function with an object that can increment and decrement ==== const counterFactory = () => { - let counter = { - 'count': 0, - 'increment': function() { - count++; - return count; + let count = 0; + return { + increment() { + count++; + return count; }, - 'decrement': function() { - count--; - return count; + decrement() { + count--; + return count; } } } - counterFactory.counter.increment(); //? + +const newCounterFactory = counterFactory(); + console.log(newCounterFactory.increment()); + console.log(newCounterFactory.decrement()); //? + console.log(typeof newCounterFactory); + console.log(typeof 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. - + // `decrement` should decrement the counter variable and return it. \ No newline at end of file From 36bdeca565c2216f33578b8f72b4bf8d10779aae Mon Sep 17 00:00:00 2001 From: JJ Ashcraft Date: Tue, 22 May 2018 18:53:36 -0400 Subject: [PATCH 8/8] completed 2/3 creative challenges, 3rd in progress --- assignments/array-methods.js | 42 +++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/assignments/array-methods.js b/assignments/array-methods.js index 06fc602a0..552c31216 100644 --- a/assignments/array-methods.js +++ b/assignments/array-methods.js @@ -73,30 +73,48 @@ 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 = []; -console.log(largeShirts); +runners.filter(runner => { + if (runner.shirt_size === 'L') { + return largeShirts.push(runner); + } +}) +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 = []; -console.log(ticketPriceTotal); +let donations = []; +runners.forEach(item => { + donations.push(item.donation); //? +}); +ticketPriceTotal.push(donations.reduce((total, amount )=> { + return total + amount; //? +})); + +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 solve 3 unique problems using one or many of the array methods listed above. // Problem 1 -// make email list and Write a thank you note to the company +// make email list to send a thank you note to the companies that donated. +let emailList = []; +runners.forEach(runner => { +emailList.push(runner.email); +console.log(emailList); //? +}); + // Problem 2 -// filter top donator list - donors over -// Problem 3 +// filter top donator list - donors over $200 let topDonors = []; runners.filter(runner => { - if (runner.donation > 200 ) { - topDonors.push([runner.company_name, '$' + runner.donation]); - } -}); + if (runner.donation > 200) { + return topDonors.push([runner.company_name, '$' + runner.donation]); //? + } +}); //? -console.log('We would like to thank the follow companies for their generous donations:' + '\n' + `${topDonors.company_name}${topDonors}`); //? +console.log(`We would like to thank the follow companies for their generous donations: ${topDonors.company_name}${topDonors}`); //? +// Problem 3 +//total shirts to order -console.log(topDonors); -//reduce total donation