From 6a4f854371a7d1974156fd4270eb58dfc47a18d3 Mon Sep 17 00:00:00 2001 From: Najja O'Connor Date: Sat, 7 Sep 2019 13:51:04 -0400 Subject: [PATCH 1/5] intial commit --- assignments/array-methods.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/assignments/array-methods.js b/assignments/array-methods.js index f3862361e..778a33c21 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 = []; +for (let i = 0; i < runners.length; i++) { + +} console.log(fullNames); // ==== Challenge 2: Use .map() ==== From 2cc51c67196189e9d8346a26f4019e2c4fd256b9 Mon Sep 17 00:00:00 2001 From: Najja O'Connor Date: Sun, 8 Sep 2019 09:19:43 -0400 Subject: [PATCH 2/5] regular update to read.me file --- README.md | 12 ++++++------ assignments/array-methods.js | 14 ++++++++++++-- assignments/closure.js | 20 +++++++++++++++++++- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 143243273..555be353e 100644 --- a/README.md +++ b/README.md @@ -7,12 +7,12 @@ With some basic JavaScript principles in hand, we can now expand our skills out **Follow these steps to set up and work on your project:** -* [ ] Create a forked copy of this project. -* [ ] Add your team lead as collaborator on Github. -* [ ] Clone your OWN version of the repository (Not Lambda's by mistake!). -* [ ] Create a new branch: git checkout -b ``. -* [ ] Implement the project on your newly created `` branch, committing changes regularly. -* [ ] Push commits: git push origin ``. +* [x] Create a forked copy of this project. +* [x] Add your team lead as collaborator on Github. +* [x] Clone your OWN version of the repository (Not Lambda's by mistake!). +* [x] Create a new branch: git checkout -b ``. +* [x] Implement the project on your newly created `` branch, committing changes regularly. +* [x] Push commits: git push origin ``. **Follow these steps for completing your project.** diff --git a/assignments/array-methods.js b/assignments/array-methods.js index 778a33c21..0162f6abe 100644 --- a/assignments/array-methods.js +++ b/assignments/array-methods.js @@ -57,15 +57,25 @@ 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 = []; +//for (let i = 0; i < runners.length; i++) { +// fullNames.push(runners[i].first_name.concat(" " + runners[i].last_name)) +//} +//console.log(fullNames); + let fullNames = []; for (let i = 0; i < runners.length; i++) { - + runners.forEach(names => { + fullNames.push(runners[i].first_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 = []; +for(let i = 0; i < runners.length; i++) { + +} console.log(firstNamesAllCaps); // ==== Challenge 3: Use .filter() ==== diff --git a/assignments/closure.js b/assignments/closure.js index 4b399c098..762850e22 100644 --- a/assignments/closure.js +++ b/assignments/closure.js @@ -3,7 +3,17 @@ // 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 ownClosure() { + let name = "Najja O'Connor"; + function alertDisplay() { + console.log("My name is" + ":" + " " + name); + } + return alertDisplay; +} + +let myFunction = ownClosure(); +myFunction(); /* STRETCH PROBLEMS, Do not attempt until you have completed all previous tasks for today's project files */ @@ -12,11 +22,19 @@ const counterMaker = () => { // IMPLEMENTATION OF counterMaker: // 1- Declare a `count` variable with a value of 0. We will be mutating it, so declare it using `let`! + let count = 0; // 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! + function counter() { + return count++; + } // 3- Return the `counter` function. + return counter; }; +counterMaker = counter(); +myCounter(); +myCounter(); // Example usage: const myCounter = counterMaker(); // myCounter(); // 1 // myCounter(); // 2 @@ -30,4 +48,4 @@ 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. -}; +}; \ No newline at end of file From e879f281ebadfb8934eae510016cc07a20fd250f Mon Sep 17 00:00:00 2001 From: Najja O'Connor Date: Mon, 9 Sep 2019 15:21:10 -0400 Subject: [PATCH 3/5] two array method questions answered --- assignments/array-methods.js | 18 +++++++++++------- assignments/closure.js | 12 ++++++++++-- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/assignments/array-methods.js b/assignments/array-methods.js index 0162f6abe..40bdc32d3 100644 --- a/assignments/array-methods.js +++ b/assignments/array-methods.js @@ -64,23 +64,27 @@ const runners = [ //console.log(fullNames); let fullNames = []; -for (let i = 0; i < runners.length; i++) { - runners.forEach(names => { - fullNames.push(runners[i].first_name) - }); +for(let i = 0; i < runners.length; i++){ +runners.forEach(function(name){ + fullNames.push(runners[i].first_name.concat(" " + runners[i].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 = []; -for(let i = 0; i < runners.length; i++) { - -} +runners.map( + (name = name => { + let uppercase = name.first_name.toUpperCase(); + firstNamesAllCaps.push(uppercase); + }) +); 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 = []; + console.log(runnersLargeSizeShirt); // ==== Challenge 4: Use .reduce() ==== diff --git a/assignments/closure.js b/assignments/closure.js index 762850e22..500b20afc 100644 --- a/assignments/closure.js +++ b/assignments/closure.js @@ -32,7 +32,7 @@ const counterMaker = () => { // 3- Return the `counter` function. return counter; }; -counterMaker = counter(); +counter() = counterMaker(); myCounter(); myCounter(); // Example usage: const myCounter = counterMaker(); @@ -45,7 +45,15 @@ myCounter(); // ==== Challenge 4: Create a counter function with an object that can increment and decrement ==== const counterFactory = () => { + increment: function increment(num) { + let counter = 0; + return num++; + } + decrement: function decrement (num) { + return counter--; + } // 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. -}; \ No newline at end of file +}; +console.log(counterFactory()); \ No newline at end of file From 90387292d1f6ae015fadb11203d75193ca0e5f67 Mon Sep 17 00:00:00 2001 From: Najja O'Connor Date: Thu, 12 Sep 2019 20:46:17 -0400 Subject: [PATCH 4/5] mvp complete --- assignments/array-methods.js | 3 +- assignments/callbacks.js | 72 ++++++++++++++++++++++++++---------- 2 files changed, 54 insertions(+), 21 deletions(-) diff --git a/assignments/array-methods.js b/assignments/array-methods.js index 40bdc32d3..bf589f612 100644 --- a/assignments/array-methods.js +++ b/assignments/array-methods.js @@ -83,8 +83,7 @@ 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 = runners.filter(shirt => shirt.shirt_size === 'L'); console.log(runnersLargeSizeShirt); // ==== Challenge 4: Use .reduce() ==== diff --git a/assignments/callbacks.js b/assignments/callbacks.js index cb72e70c9..5602f4131 100644 --- a/assignments/callbacks.js +++ b/assignments/callbacks.js @@ -37,33 +37,67 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum']; const test2 = firstItem(items, logExorbitantPrice); console.log(test2); // "this Pencil is worth a million dollars!" */ +//callback function +function findLength(x) { + console.log(x) +} - +//function given callback function getLength(arr, cb) { - // getLength passes the length of the array into the callback. + return cb(arr.length); } -function last(arr, cb) { - // last passes the last item of the array into the callback. -} +getLength(items, findLength) -function sumNums(x, y, cb) { - // sumNums adds two numbers (x, y) and passes the result to the callback. +function findLast(x) { + console.log(x) } -function multiplyNums(x, y, cb) { - // multiplyNums multiplies two numbers and passes the result to the callback. +function last(arr, cb) { + return cb(arr[3]) } -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. -} +last(items, findLast) -/* STRETCH PROBLEM */ +//addUp is callback -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. -} + //function callback is being passed into + function sumNums(x, y, callback) { + return callback(x + y); + } + + sumNums(3, 4, function(addUp){ + console.log(addUp) + }) + + function multiplyNums(x, y, callback) { + return callback(x * y); + } + + multiplyNums(50, 666, function(multiply){ + console.log(multiply) ; + }) + + function isPresent(item, list) { + for (let i = 0; i < list.length; i++) { + if (list[i] === item) { + return true; + } else { + return 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(items, ) + + /* STRETCH PROBLEM */ + + 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. + } From 9707aca498743177c9042361fc10c10ca58c0261 Mon Sep 17 00:00:00 2001 From: Najja O'Connor Date: Thu, 12 Sep 2019 20:47:06 -0400 Subject: [PATCH 5/5] mvp done actually this time --- assignments/callbacks.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assignments/callbacks.js b/assignments/callbacks.js index 5602f4131..7f984255c 100644 --- a/assignments/callbacks.js +++ b/assignments/callbacks.js @@ -78,7 +78,7 @@ last(items, findLast) console.log(multiply) ; }) - function isPresent(item, list) { + function contain (item, list) { for (let i = 0; i < list.length; i++) { if (list[i] === item) { return true;