From d413d4be92be8f9f4a7572582b1df8cf87fc1c2b Mon Sep 17 00:00:00 2001 From: jarrodskahill Date: Tue, 17 Sep 2019 20:32:50 -0700 Subject: [PATCH 1/4] testing push --- assignments/array-methods.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/assignments/array-methods.js b/assignments/array-methods.js index f3862361e..cbd5395b5 100644 --- a/assignments/array-methods.js +++ b/assignments/array-methods.js @@ -58,6 +58,9 @@ 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 (elements =>{ + fullNames.push(`${elements.first_name} ${elements.last_name}`) +}); console.log(fullNames); // ==== Challenge 2: Use .map() ==== From dc4e9c2e5272777b660b2bc482e2e5b178558451 Mon Sep 17 00:00:00 2001 From: jarrodskahill Date: Tue, 17 Sep 2019 21:38:52 -0700 Subject: [PATCH 2/4] Finishing callbacks --- assignments/array-methods.js | 17 +++++++++++++++-- assignments/callbacks.js | 3 ++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/assignments/array-methods.js b/assignments/array-methods.js index cbd5395b5..4a26dadc2 100644 --- a/assignments/array-methods.js +++ b/assignments/array-methods.js @@ -66,16 +66,29 @@ 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((Atlas, index) => { + firstNamesAllCaps[index] = Atlas.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 = []; +let = runnersLargeSizeShirt = [] +runnersLargeSizeShirt = runners.filter( largeman => { + if (largeman.shirt_size === 'L'){ + return largeman; + } + +}) 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; +let ticketPriceTotal = []; +ticketPriceTotal = runners.reduce((totalValue, runner) => { + return totalValue + runner.donation; +}, 0); + console.log(ticketPriceTotal); // ==== Challenge 5: Be Creative ==== diff --git a/assignments/callbacks.js b/assignments/callbacks.js index cb72e70c9..4b06b227d 100644 --- a/assignments/callbacks.js +++ b/assignments/callbacks.js @@ -7,7 +7,7 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum']; // GIVEN THIS PROBLEM: function firstItem(arr, cb) { - // firstItem passes the first item of the given array to the callback function. + firstItem passes the first item of the given array to the callback function. } // SOLUTION: @@ -41,6 +41,7 @@ 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) } function last(arr, cb) { From 59a904b2a75e7c341fbe3aa5e27660cd38f75647 Mon Sep 17 00:00:00 2001 From: jarrodskahill Date: Tue, 17 Sep 2019 21:58:35 -0700 Subject: [PATCH 3/4] finished callbacks --- assignments/callbacks.js | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/assignments/callbacks.js b/assignments/callbacks.js index 4b06b227d..19b20ad2b 100644 --- a/assignments/callbacks.js +++ b/assignments/callbacks.js @@ -41,25 +41,50 @@ 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) + return cb (arr.length); } +getLength(items, function(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]); +}; +last(items, function(thelastone) +{ + console.log(thelastone); +}); function sumNums(x, y, cb) { // sumNums adds two numbers (x, y) and passes the result to the callback. + return cb(x, y); } +sumNums(4, 5, function(x, y){ + console.log(x + y); +}); function multiplyNums(x, y, cb) { // multiplyNums multiplies two numbers and passes the result to the callback. + return cb(x, y); } +multiplyNums(4, 5, function(x, y){ + console.log(x * y); +}); 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. + if(list.includes(item)){ + return cb(true); + } else { + return cb(false); + } } +contains('Pencil', items, function(result){ + console.log(result); +}); + /* STRETCH PROBLEM */ From 7d1f33259bed9f887d7456b9ab06f92720b58846 Mon Sep 17 00:00:00 2001 From: jarrodskahill Date: Tue, 17 Sep 2019 22:10:17 -0700 Subject: [PATCH 4/4] finished closure, done with MVP --- assignments/closure.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/assignments/closure.js b/assignments/closure.js index 4b399c098..4cda80da5 100644 --- a/assignments/closure.js +++ b/assignments/closure.js @@ -3,6 +3,22 @@ // 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. +function sayHello(greeting) { + const hello = greeting; + const name = 'Jarrod'; + console.log(`${hello}. How you doinnnn?`); + + function answer() { + const whatsup = "What's up" + const answer = "I'm doing great man!" + console.log(`${whatsup} ${name}, ${answer}`); + } + + answer(); +} + +console.log(sayHello('yo')) + /* STRETCH PROBLEMS, Do not attempt until you have completed all previous tasks for today's project files */