From 6af8f44e4ea3b808ec1deb136383430c6fc19270 Mon Sep 17 00:00:00 2001 From: barbarof Date: Fri, 4 Oct 2019 20:17:47 -0500 Subject: [PATCH 1/4] challenge2 --- assignments/array-methods.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/assignments/array-methods.js b/assignments/array-methods.js index f3862361e..88ec31af9 100644 --- a/assignments/array-methods.js +++ b/assignments/array-methods.js @@ -58,12 +58,24 @@ 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 = []; -console.log(fullNames); + runners.forEach(function(runner){ + fullNames.push(`${runner.first_name} ${runner.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 = []; -console.log(firstNamesAllCaps); +runners.map(function(runner){ + firstNamesAllCaps.push(`${runner.first_name} ${runner.last_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. From bf54fa807b6edd4a8830c0972b559b1d8943f490 Mon Sep 17 00:00:00 2001 From: barbarof Date: Mon, 7 Oct 2019 16:02:16 -0500 Subject: [PATCH 2/4] update array-methods --- assignments/array-methods.js | 18 +++++++++++++----- assignments/callbacks.js | 7 +++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/assignments/array-methods.js b/assignments/array-methods.js index 88ec31af9..27581a424 100644 --- a/assignments/array-methods.js +++ b/assignments/array-methods.js @@ -74,18 +74,26 @@ runners.map(function(runner){ }); - - - // ==== 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 = []; +runners.filter(function(runner){ + runnersLargeSizeShirt.push(runner.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; -console.log(ticketPriceTotal); +let ticketPriceTotal = runners.reduce((acc,currentValue)=>acc+currentValue); + + + + console.log(runners.reduce(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/callbacks.js b/assignments/callbacks.js index cb72e70c9..2fa9d1b1f 100644 --- a/assignments/callbacks.js +++ b/assignments/callbacks.js @@ -40,22 +40,29 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum']; function getLength(arr, cb) { + return cb(arr.length); // getLength passes the length of the array into the callback. } function last(arr, cb) { + return cb(arr.length -1); // last passes the last item of the array into the callback. } function sumNums(x, y, cb) { + + return cb (x + y); // sumNums adds two numbers (x, y) and passes the result to the callback. } function multiplyNums(x, y, cb) { + let total= x*y; + return cb(total) // multiplyNums multiplies two numbers and passes the result to the callback. } function contains(item, list, cb) { + for (le) // 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 23aed51452a0d1184e623af15351275799408f08 Mon Sep 17 00:00:00 2001 From: barbarof Date: Mon, 7 Oct 2019 16:20:03 -0500 Subject: [PATCH 3/4] update callback --- assignments/callbacks.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/assignments/callbacks.js b/assignments/callbacks.js index 2fa9d1b1f..06b6706bd 100644 --- a/assignments/callbacks.js +++ b/assignments/callbacks.js @@ -62,7 +62,11 @@ function multiplyNums(x, y, cb) { } function contains(item, list, cb) { - for (le) + for(let i =0 ; i Date: Mon, 7 Oct 2019 20:23:36 -0500 Subject: [PATCH 4/4] update calback --- assignments/callbacks.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/assignments/callbacks.js b/assignments/callbacks.js index 06b6706bd..adbc6c229 100644 --- a/assignments/callbacks.js +++ b/assignments/callbacks.js @@ -41,6 +41,8 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum']; function getLength(arr, cb) { return cb(arr.length); + +} // getLength passes the length of the array into the callback. }