diff --git a/README.md b/README.md index 6288977c2..d5c0b202f 100644 --- a/README.md +++ b/README.md @@ -7,34 +7,34 @@ 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 project manager 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 project manager 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 project manager as a reviewer on the pull-request -* [ ] Your project manager 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 project manager as a reviewer on the pull-request +* [X] Your project manager will count the project as complete by merging the branch back into master. ## Task 2: Higher Order Functions and Callbacks This task focuses on getting practice with higher order functions and callback functions by giving you an array of values and instructions on what to do with that array. -* [ ] Review the contents of the [callbacks.js](assignments/callbacks.js) file. Notice you are given an array at the top of the page. Use that array to aid you with your functions. +* [X] Review the contents of the [callbacks.js](assignments/callbacks.js) file. Notice you are given an array at the top of the page. Use that array to aid you with your functions. -* [ ] Complete the problems provided to you but skip over stretch problems until you are complete with every other JS file first. +* [X] Complete the problems provided to you but skip over stretch problems until you are complete with every other JS file first. ## Task 3: Array Methods Use `.forEach()`, `.map()`, `.filter()`, and `.reduce()` to loop over an array with 50 objects in it. The [array-methods.js](assignments/array-methods.js) file contains several challenges built around a fundraising 5K fun run event. -* [ ] Review the contents of the [array-methods.js](assignments/array-methods.js) file. +* [X] Review the contents of the [array-methods.js](assignments/array-methods.js) file. -* [ ] Complete the problems provided to you but skip over stretch problems until you are complete with every other JS file first. +* [X] Complete the problems provided to you but skip over stretch problems until you are complete with every other JS file first. * [ ] Notice the last three problems are up to you to create and solve. This is an awesome opportunity for you to push your critical thinking about array methods, have fun with it. @@ -44,8 +44,8 @@ We have learned that closures allow us to access values in scope that have alrea **Hint: Utilize debugger statements in your code in combination with your developer tools to easily identify closure values.** -* [ ] Review the contents of the [closure.js](assignments/closure.js) file. -* [ ] Complete the problems provided to you but skip over stretch problems until you are complete with every other JS file first. +* [X] Review the contents of the [closure.js](assignments/closure.js) file. +* [X] Complete the problems provided to you but skip over stretch problems until you are complete with every other JS file first. ## Stretch Goals diff --git a/assignments/array-methods.js b/assignments/array-methods.js index f692c35c6..75527fe09 100644 --- a/assignments/array-methods.js +++ b/assignments/array-methods.js @@ -56,28 +56,77 @@ const runners = [{"id":1,"first_name":"Charmain","last_name":"Seiler","email":"c // ==== 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 into a new array called fullName. let fullName = []; -console.log(fullName); + +runners.forEach(item => fullName.push(item['first_name'] + ' ' + item['last_name'])); + +console.log('Full Names here: ', fullName); + +// It looks like .forEach() and .push() need to be used together if they are going to add the values into a new array // ==== Challenge 2: Use .map() ==== // The event director needs to have all the runner's first names converted to uppercase because the director BECAME DRUNK WITH POWER. Convert each first name into all caps and log the result let allCaps = []; -console.log(allCaps); + +allCaps = runners.map(item => item['first_name'].toUpperCase()); +console.log('First Names in All CAPS: ', allCaps); + +// .map() includes the .push() within itself to add elements back into the allCaps array // ==== Challenge 3: Use .filter() ==== // The large shirts won't be available for the event due to an ordering issue. Get a list of runners with large sized shirts so they can choose a different size. Return an array named largeShirts that contains information about the runners that have a shirt size of L and log the result let largeShirts = []; -console.log(largeShirts); + +largeShirts = runners.filter((item) => { + return item['shirt_size'] === 'L'; +}); + +console.log('These have Large shirts: ', largeShirts); // ==== Challenge 4: Use .reduce() ==== // The donations need to be tallied up and reported for tax purposes. Add up all the donations into a ticketPriceTotal array and log the result let ticketPriceTotal = []; -console.log(ticketPriceTotal); + +ticketPriceTotal = runners.reduce((total, item) => { + return total += item['donation']; +}, 0); + +console.log('Total Ticket Donations: $', 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 1 - Which individuals donated over $250? + +let bigGivers = []; + +bigGivers = runners.filter((item) => { + return item['donation'] > 250; +}); + +console.log('We got some big givers over here: ', bigGivers); + + +// Problem 2 - Which company had the most participants? + +let activeCompany = []; + +activeCompany = runners.forEach(item => activeCompany.push(item['company'])); + +// activeCompany = runners.filter((item) => { +// return item['company']; +// }); + +console.log('Most Active Company', activeCompany); + + +// Problem 3 - Show me emails of everyone with a Large T-shirt? + +let emails = []; + +emails = runners.filter((item) => { + return item['shirt_size'] === 'L'; +}); -// Problem 2 +console.log('These are Large Emails: ', emails); -// Problem 3 \ No newline at end of file +// I can't get just the emails to show... \ No newline at end of file diff --git a/assignments/callbacks.js b/assignments/callbacks.js index c1c013800..0434453df 100644 --- a/assignments/callbacks.js +++ b/assignments/callbacks.js @@ -25,26 +25,78 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum']; */ +// CALLBACK 1 + function getLength(arr, cb) { // getLength passes the length of the array into the callback. + return cb(arr.length) } +getLength(items, function(length) { + console.log('Length: ', length) +}); + + +// CALLBACK 2 + function last(arr, cb) { // last passes the last item of the array into the callback. + let lastIndex = arr.length - 1; + // console.log(lastIndex); + return cb(arr[lastIndex]); } +last(items, function(lastItem) { + console.log('Last Item: ', lastItem) +}); + + +// CALLBACK 3 + function sumNums(x, y, cb) { // sumNums adds two numbers (x, y) and passes the result to the callback. + let addNumbers = x + y; + return cb(addNumbers); } +sumNums(7, 8, function(additions) { + console.log('Sum of Numbers: ', additions); +}); + + +// CALLBACK 4 + function multiplyNums(x, y, cb) { // multiplyNums multiplies two numbers and passes the result to the callback. + let multiNumber = x * y; + return cb(multiNumber); } +multiplyNums(4, 8, function(multis) { + console.log('Multiply Numbers: ', multis); +}); + + +// CALLBACK 5 + 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. -} + let x = list.includes(item); + if (cb(x)) { + return true; + } else false; +}; + +var a = 'Pencil'; +contains(a, items, function(containsIt) { + console.log(`Does it contain '${a}'? : `, containsIt); +}); + +var b = 'parks'; +contains(b, items, function(containsIt) { + console.log(`Does it contain '${b}'? : `, containsIt); +}); /* STRETCH PROBLEM */ diff --git a/assignments/closure.js b/assignments/closure.js index 4307524fc..343251b52 100644 --- a/assignments/closure.js +++ b/assignments/closure.js @@ -1,6 +1,11 @@ // ==== Challenge 1: Write your own closure ==== // Write a simple closure of your own creation. Keep it simple! +const closure = 'I am closure'; +function getClosure() { + return closure; +} +console.log('This is my function getting closure: ', getClosure()); /* STRETCH PROBLEMS, Do not attempt until you have completed all previous tasks for today's project files */