From f8dcb708e61a891582805bb45f76b34da3cae115 Mon Sep 17 00:00:00 2001 From: wchamber01 <52251104+wchamber01@users.noreply.github.com> Date: Wed, 18 Sep 2019 22:41:12 -0400 Subject: [PATCH] finished up --- assignments/.vscode/launch.json | 14 ++++++++++++++ assignments/array-methods.js | 12 ++++++++++-- assignments/callbacks.js | 26 ++++++++++++++++++++------ assignments/closure.js | 10 ++++++++++ 4 files changed, 54 insertions(+), 8 deletions(-) create mode 100644 assignments/.vscode/launch.json diff --git a/assignments/.vscode/launch.json b/assignments/.vscode/launch.json new file mode 100644 index 000000000..c9de85247 --- /dev/null +++ b/assignments/.vscode/launch.json @@ -0,0 +1,14 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Launch Program", + "program": "${workspaceFolder}\\closure.js" + } + ] +} \ No newline at end of file diff --git a/assignments/array-methods.js b/assignments/array-methods.js index f3862361e..9ee7a594f 100644 --- a/assignments/array-methods.js +++ b/assignments/array-methods.js @@ -58,21 +58,29 @@ 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(person=>fullNames.push (`${person.first_name} ${person.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 = []; +firstNamesAllCaps = runners.map(person=>person.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(person=>person.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; +let ticketPriceTotal = runners.reduce((total, runner) => { + total += runner.donation; + return total; +}, 0) console.log(ticketPriceTotal); // ==== Challenge 5: Be Creative ==== diff --git a/assignments/callbacks.js b/assignments/callbacks.js index cb72e70c9..0cfeb0119 100644 --- a/assignments/callbacks.js +++ b/assignments/callbacks.js @@ -40,30 +40,44 @@ 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 passes the length of the array into the callback. +} +console.log(getLength(items, things)) + +function things(things){ + return things; } function last(arr, cb) { + return cb(arr[arr.length-1]) // last passes the last item of the array into the callback. } +console.log(last(items, thing=>thing)) function sumNums(x, y, cb) { + return cb(x+y); // sumNums adds two numbers (x, y) and passes the result to the callback. } +console.log(sumNums(3,5, things)); function multiplyNums(x, y, cb) { + return cb(x*y); // multiplyNums multiplies two numbers and passes the result to the callback. } +console.log(multiplyNums(3,5, things)); 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. -} + +return cb(list.includes(item))} +// contains checks if an item is present inside of the given array/list. +// Pass true to the callback if it is, otherwise pass false. +console.log(contains("stress ball", items, things)) /* STRETCH PROBLEM */ -function removeDuplicates(array, cb) { +// function removeDuplicates(array, cb) { // removeDuplicates removes all duplicate values from the given array. // Pass the duplicate free array to the callback function. // Do not mutate the original array. -} +// } \ No newline at end of file diff --git a/assignments/closure.js b/assignments/closure.js index 4b399c098..9c1360c63 100644 --- a/assignments/closure.js +++ b/assignments/closure.js @@ -4,6 +4,16 @@ // that manipulates variables defined in the outer scope. // The outer scope can be a parent function, or the top level of the script. +function floridaWeather(){ + const weather = "muggy"; + console.log(`The weather in Florida is ${weather}!`); + + function okeechobeeWeather(){ + const adverb = "extraordinarily" + console.log(`The weather in Okeechobee is ${adverb} ${weather}!`); + } +} + /* STRETCH PROBLEMS, Do not attempt until you have completed all previous tasks for today's project files */