From 240d4252ec2d39f0ad77cb2d627e91ea658cce5a Mon Sep 17 00:00:00 2001 From: Amber Lowe <52145666+amberlowe1001@users.noreply.github.com> Date: Tue, 15 Oct 2019 12:03:28 -0700 Subject: [PATCH 1/7] Update array-methods.js --- assignments/array-methods.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/assignments/array-methods.js b/assignments/array-methods.js index f3862361e..f9741ca49 100644 --- a/assignments/array-methods.js +++ b/assignments/array-methods.js @@ -58,21 +58,28 @@ 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 (runner => fullName.push( `${runner.first_Name}` `${ runner.last_name }`)); +console.log(fullName); // ==== 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( runners => runners.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(runner => 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; +let allPrices = 0; +allPrices = runners.map(runner => runner.donation); +ticketPriceTotal.push(allPrices.reduce((a, c) => a + c)); console.log(ticketPriceTotal); // ==== Challenge 5: Be Creative ==== @@ -82,4 +89,4 @@ console.log(ticketPriceTotal); // Problem 2 -// Problem 3 \ No newline at end of file +// Problem 3 From aed0fad260c04ab11957ab6fedd35f456f4fe2fa Mon Sep 17 00:00:00 2001 From: Amber Lowe <52145666+amberlowe1001@users.noreply.github.com> Date: Tue, 15 Oct 2019 12:32:35 -0700 Subject: [PATCH 2/7] Update array-methods.js completed array-methods --- assignments/array-methods.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/assignments/array-methods.js b/assignments/array-methods.js index f9741ca49..119f41668 100644 --- a/assignments/array-methods.js +++ b/assignments/array-methods.js @@ -86,7 +86,20 @@ 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 create and then solve 3 unique problems using one or many of the array methods listed above. // Problem 1 +let allCompanies = runners.map(runner => runner.company_name); +let uniqueCompanies = Array.from(new Set(allCompanies)); +let uniqueCompanies2 = allCompanies.filter((co, index) => allCompanies.indexOf(co) >= index); +console.log(uniqueCompanies); // Problem 2 +let allDonorAmtByLastName = runners.map(runner => `${runner.last_name}: $${ runner.donation }` ); +console.log(allDonorAmtByLastName); + // Problem 3 +let dotCompCo = []; +dotCompCo = runners.filter(runner => runner.email.includes(`.com`)); +let allDotCompCoPrices = 0; +allDotCompCoPrices = dotCompCo.map(runner => runner.donation).reduce((a, c) => a + c); +let avgTicketPriceTotal = ticketPriceTotal/runners.length; +console.log(`Average donation price from.com emails ${avgDotCompCoPrices > avgTicketPriceTotal ? `is` : `is not`} more than the average donation price for all companies.`); From 197c38075d0a707586fa28f2fa7cc7ee6ae2d2d3 Mon Sep 17 00:00:00 2001 From: Amber Lowe <52145666+amberlowe1001@users.noreply.github.com> Date: Tue, 15 Oct 2019 13:00:07 -0700 Subject: [PATCH 3/7] Update callbacks.js call backs complete-including strech goal of removal of duplicates --- assignments/callbacks.js | 50 +++++++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/assignments/callbacks.js b/assignments/callbacks.js index cb72e70c9..ff81adb9f 100644 --- a/assignments/callbacks.js +++ b/assignments/callbacks.js @@ -2,7 +2,13 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum']; -/* +function getLength(arr, cb) { + cb(arr.length); +}; + + + +/* // GIVEN THIS PROBLEM: @@ -40,30 +46,58 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum']; function getLength(arr, cb) { + cb(arr.length); // getLength passes the length of the array into the callback. -} +}; +getLength(items, function (lenny) { + console.log(lenny); +}); function last(arr, cb) { + cb(arr[arr.length - 1]); // last passes the last item of the array into the callback. -} +}; +last(items, function (showLast) { + console.log(showLast); +}); function sumNums(x, y, cb) { + cb(x + y); // sumNums adds two numbers (x, y) and passes the result to the callback. -} +}; +sumNums(2, 3, function (adder) { + console.log(adder); +}); function multiplyNums(x, y, cb) { + cb(x * y); // multiplyNums multiplies two numbers and passes the result to the callback. -} +}; +multiplyNums(2, 3, function (product) { + console.log(product); +}); function contains(item, list, cb) { + cb(list.includes(item) ? true : false); // contains checks if an item is present inside of the given array/list. // Pass true to the callback if it is, otherwise pass false. -} +}; +contains(`Notebook`, items, function (hit) { + console.log(hit); -/* STRETCH PROBLEM */ +}); +/* STRETCH PROBLEM */ +const itemsDoubled = [`Pencil`, `Notebook`, `yo-yo`, `Gum`, `Notebook`, `yo-yo`, `Gum`]; function removeDuplicates(array, cb) { + + let uniqueItems = Array.from(new Set(array)); + cb(uniqueItems) +}; +removeDuplicates(itemsDoubled, function (nonDupe) { + console.log(nonDupe) +}); // removeDuplicates removes all duplicate values from the given array. // Pass the duplicate free array to the callback function. // Do not mutate the original array. -} + From d7ed8b769ff8269e29666b0eed56d345596f28b9 Mon Sep 17 00:00:00 2001 From: Amber Lowe <52145666+amberlowe1001@users.noreply.github.com> Date: Tue, 15 Oct 2019 13:39:29 -0700 Subject: [PATCH 4/7] Update closure.js assignment complete --- assignments/closure.js | 50 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/assignments/closure.js b/assignments/closure.js index 4b399c098..48d5d5d2a 100644 --- a/assignments/closure.js +++ b/assignments/closure.js @@ -4,30 +4,72 @@ // that manipulates variables defined in the outer scope. // The outer scope can be a parent function, or the top level of the script. +function adder(num1) { + return function (num2) { + return num1 + num2; + } +}; +let add5 = adder(5); +let add7 = adder(7); +console.log(add7); /* STRETCH PROBLEMS, Do not attempt until you have completed all previous tasks for today's project files */ // ==== Challenge 2: Implement a "counter maker" function ==== const counterMaker = () => { + const counter = () => { + let count = 0; + return function () { + let count = 0; + return function () { + return ++count; + } + }; + console.log(newCounter); + console.log(newCounter); + console.log(newCounter); + // IMPLEMENTATION OF counterMaker: // 1- Declare a `count` variable with a value of 0. We will be mutating it, so declare it using `let`! // 2- Declare a function `counter`. It should increment and return `count`. // NOTE: This `counter` function, being nested inside `counterMaker`, // "closes over" the `count` variable. It can "see" it in the parent scope! - // 3- Return the `counter` function. -}; + // 3- Return the `counter` funnction. + // Example usage: const myCounter = counterMaker(); // myCounter(); // 1 // myCounter(); // 2 // ==== Challenge 3: Make `counterMaker` more sophisticated ==== // It should have a `limit` parameter. Any counters we make with `counterMaker` + const counterMaker = counter(); + // newCounter(); //1 + // newCounter(); //2 + console.log(newCounter()); + console.log(newCounter()); + // will refuse to go over the limit, and start back at 1. // ==== Challenge 4: 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. -}; + // `decrement` should decrement the counter variable and return it.c + let count = 0; { + + + return { + increment: function () { + return ++count; + + }, + decrement: function () { + return --count; + }, + } + + }; + console.log(counterFactory.increment()); + console.log(counterFactory.increment()); + console.log(counterFactory.decrement()) From fdc6fcae0fdb42b0c20608e376e763a2653ef691 Mon Sep 17 00:00:00 2001 From: Amber Lowe <52145666+amberlowe1001@users.noreply.github.com> Date: Tue, 15 Oct 2019 14:09:36 -0700 Subject: [PATCH 5/7] Create launch.json --- .vscode/launch.json | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 000000000..ab4a7691c --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,25 @@ +{ + // 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", + "name": "vscode-jest-tests", + "request": "launch", + "args": [ + "--runInBand" + ], + "cwd": "${workspaceFolder}", + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen", + "disableOptimisticBPs": true, + "program": "${workspaceFolder}/node_modules/jest/bin/jest" + } + ] +} From cf1b07f3ff892342a646c60a65fc6f4ed639c09e Mon Sep 17 00:00:00 2001 From: Amber Lowe <52145666+amberlowe1001@users.noreply.github.com> Date: Wed, 16 Oct 2019 13:02:51 -0700 Subject: [PATCH 6/7] final commit there are still four errors that i can not find a solution to --- assignments/array-methods.js | 4 ++-- assignments/closure.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/assignments/array-methods.js b/assignments/array-methods.js index 119f41668..d1efe96ba 100644 --- a/assignments/array-methods.js +++ b/assignments/array-methods.js @@ -57,8 +57,8 @@ 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 (runner => fullName.push( `${runner.first_Name}` `${ runner.last_name }`)); +let fullName = []; +runners.forEach(runner => fullName.push( `${runner.first_name} ${ runner.last_name}`)); console.log(fullName); // ==== Challenge 2: Use .map() ==== diff --git a/assignments/closure.js b/assignments/closure.js index 48d5d5d2a..7f1139269 100644 --- a/assignments/closure.js +++ b/assignments/closure.js @@ -69,7 +69,7 @@ const counterFactory = () => { }, } - }; + console.log(counterFactory.increment()); console.log(counterFactory.increment()); console.log(counterFactory.decrement()) From f0c44fe5c7ca0540d02673060d9555224fc747d0 Mon Sep 17 00:00:00 2001 From: Amber Lowe <52145666+amberlowe1001@users.noreply.github.com> Date: Tue, 3 Dec 2019 23:09:55 -0800 Subject: [PATCH 7/7] mvp --- assignments/array-methods.js | 2 +- assignments/closure.js | 74 +++++++++++++++++++----------------- 2 files changed, 41 insertions(+), 35 deletions(-) diff --git a/assignments/array-methods.js b/assignments/array-methods.js index d1efe96ba..6bf96b502 100644 --- a/assignments/array-methods.js +++ b/assignments/array-methods.js @@ -64,7 +64,7 @@ console.log(fullName); // ==== 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( runners => runners.first_Name.toUpperCase()); +firstNamesAllCaps = runners.map( runners => runners.first_name.toUpperCase()); console.log(firstNamesAllCaps); diff --git a/assignments/closure.js b/assignments/closure.js index 7f1139269..546e43719 100644 --- a/assignments/closure.js +++ b/assignments/closure.js @@ -4,7 +4,7 @@ // that manipulates variables defined in the outer scope. // The outer scope can be a parent function, or the top level of the script. -function adder(num1) { +function add(num1) { return function (num2) { return num1 + num2; } @@ -18,11 +18,14 @@ console.log(add7); // ==== Challenge 2: Implement a "counter maker" function ==== const counterMaker = () => { - const counter = () => { + const counter = () => + { let count = 0; - return function () { + return function () + { let count = 0; - return function () { + return function () + { return ++count; } }; @@ -30,46 +33,49 @@ const counterMaker = () => { console.log(newCounter); console.log(newCounter); - // IMPLEMENTATION OF counterMaker: - // 1- Declare a `count` variable with a value of 0. We will be mutating it, so declare it using `let`! - // 2- Declare a function `counter`. It should increment and return `count`. - // NOTE: This `counter` function, being nested inside `counterMaker`, - // "closes over" the `count` variable. It can "see" it in the parent scope! - // 3- Return the `counter` funnction. + // IMPLEMENTATION OF counterMaker: + // 1- Declare a `count` variable with a value of 0. We will be mutating it, so declare it using `let`! + // 2- Declare a function `counter`. It should increment and return `count`. + // NOTE: This `counter` function, being nested inside `counterMaker`, + // "closes over" the `count` variable. It can "see" it in the parent scope! + // 3- Return the `counter` funnction. -// Example usage: const myCounter = counterMaker(); -// myCounter(); // 1 -// myCounter(); // 2 + // Example usage: const myCounter = counterMaker(); + // myCounter(); // 1 + // myCounter(); // 2 -// ==== Challenge 3: Make `counterMaker` more sophisticated ==== -// It should have a `limit` parameter. Any counters we make with `counterMaker` + // ==== Challenge 3: Make `counterMaker` more sophisticated ==== + // It should have a `limit` parameter. Any counters we make with `counterMaker` const counterMaker = counter(); // newCounter(); //1 // newCounter(); //2 console.log(newCounter()); console.log(newCounter()); -// will refuse to go over the limit, and start back at 1. + // will refuse to go over the limit, and start back at 1. -// ==== Challenge 4: 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.c - let count = 0; { + // // ==== Challenge 4: 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.c + // let count = 0; { - return { - increment: function () { - return ++count; - - }, - decrement: function () { - return --count; - }, - } + // return { + // increment: function () + // { + // return ++count; + // }, + // decrement: function () + // { + // return --count; + // }, + // } + // } + // console.log(counterFactory.increment()); + // console.log(counterFactory.decrement); + // } - console.log(counterFactory.increment()); - console.log(counterFactory.increment()); - console.log(counterFactory.decrement())