diff --git a/README.md b/README.md index 143243273..ff27924a7 100644 --- a/README.md +++ b/README.md @@ -7,18 +7,18 @@ 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.** -* [ ] Submit a Pull-Request to merge Branch into master (student's Repo). **Please don't merge your own pull request** -* [ ] Add your team lead as a reviewer on the pull-request -* [ ] Your team lead will count the project as complete by merging the branch back into master. +* [x] Submit a Pull-Request to merge Branch into master (student's Repo). **Please don't merge your own pull request** +* [x] Add your team lead as a reviewer on the pull-request +* [x] Your team lead will count the project as complete by merging the branch back into master. ## Task 1: Higher Order Functions and Callbacks @@ -50,4 +50,4 @@ We have learned that closures allow us to access values in scope that have alrea ## Stretch Goals * [ ] Go back through the stretch problems that you skipped over and complete as many as you can. -* [ ] Look up what an IIFE is in JavaScript and experiment with them \ No newline at end of file +* [ ] Look up what an IIFE is in JavaScript and experiment with them diff --git a/assignments/array-methods.js b/assignments/array-methods.js index f3862361e..c76ae19b4 100644 --- a/assignments/array-methods.js +++ b/assignments/array-methods.js @@ -58,28 +58,37 @@ 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(function(runners){ return fullNames.push(`${runners.first_name} ${runners.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 = []; +runners.map(function(runners){ return firstNamesAllCaps.push(`${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 = []; + + 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; + ticketPriceTotal = runners.reduce(function(total, runner){ + return total += runner.donation; + }, 0); console.log(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. // Problem 1 + // Problem 2 -// Problem 3 \ No newline at end of file +// Problem 3 diff --git a/assignments/callbacks.js b/assignments/callbacks.js index cb72e70c9..5ad9ff77e 100644 --- a/assignments/callbacks.js +++ b/assignments/callbacks.js @@ -2,7 +2,7 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum']; -/* + // GIVEN THIS PROBLEM: @@ -36,30 +36,41 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum']; const test2 = firstItem(items, logExorbitantPrice); console.log(test2); // "this Pencil is worth a million dollars!" -*/ + function getLength(arr, cb) { // getLength passes the length of the array into the callback. + return (arr.length); } +console.log(getLength(items)); function last(arr, cb) { // last passes the last item of the array into the callback. +return (arr[3]); } +console.log(last(items)); function sumNums(x, y, cb) { // sumNums adds two numbers (x, y) and passes the result to the callback. + return (x + y) } +console.log(sumNums(4,6)); function multiplyNums(x, y, cb) { // multiplyNums multiplies two numbers and passes the result to the callback. + return (x * y) } +console.log(multiplyNums(4,6)); 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 `the list has ${item}`; + } } - +console.log(contains(items, 'Pencil')) /* STRETCH PROBLEM */ function removeDuplicates(array, cb) { diff --git a/assignments/closure.js b/assignments/closure.js index 4b399c098..2ec1c6bcd 100644 --- a/assignments/closure.js +++ b/assignments/closure.js @@ -2,7 +2,10 @@ // Write a closure of your own creation. // 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. +//er scope can be a parent function, or the top level of the script. +let i = 10; + +function parent() { let j = 20; function child() {let k = 9; let total = i + j * k; return total} return child} /* STRETCH PROBLEMS, Do not attempt until you have completed all previous tasks for today's project files */ @@ -16,6 +19,12 @@ const counterMaker = () => { // 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. + + let count = 0; + function myCounter() { + counter = counter += count; + } +return counter; }; // Example usage: const myCounter = counterMaker(); // myCounter(); // 1 @@ -24,10 +33,24 @@ const counterMaker = () => { // ==== Challenge 3: Make `counterMaker` more sophisticated ==== // It should have a `limit` parameter. Any counters we make with `counterMaker` // will refuse to go over the limit, and start back at 1. +const countMaker = (limit) => { + let count = 0; + function myCounter() { + limit = count < count.length; + + } +} + // ==== 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. + function increment() { +// counter++ + }; + function decrement() { +// counter-- + }; };