Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<firstName-lastName>`.
* [ ] Implement the project on your newly created `<firstName-lastName>` branch, committing changes regularly.
* [ ] Push commits: git push origin `<firstName-lastName>`.
* [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 `<firstName-lastName>`.
* [x] Implement the project on your newly created `<firstName-lastName>` branch, committing changes regularly.
* [x] Push commits: git push origin `<firstName-lastName>`.

**Follow these steps for completing your project.**

Expand All @@ -24,17 +24,17 @@ With some basic JavaScript principles in hand, we can now expand our skills out

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 2: 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.

Expand All @@ -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

Expand Down
18 changes: 17 additions & 1 deletion assignments/array-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,44 @@ 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(arr => fullNames.push(`${arr.first_name} ${arr.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(arr => firstNamesAllCaps.push(arr.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(lSize => lSize.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;
ticketPriceTotal = runners.reduce((ticketPriceTotal,runner) => ticketPriceTotal += 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
//List all emails for marketing reaons.
let allEmails = []
runners.forEach(runner => allEmails.push(`${runner.email}`));
console.log(allEmails);

// Problem 2
//List all donors over 280.
let highDonors = []
highDonors = runners.filter(amount => amount.donation >280);
console.log(highDonors);

// Problem 3
// Problem 3
//People from Skinix company get special treatment at the foodcourt, list people fron this company
let teams = []
teams = runners.filter(company => company.company_name === "Skinix");
console.log(teams);
11 changes: 11 additions & 0 deletions assignments/callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,35 @@ 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(items, console.log);

function last(arr, cb) {
// last passes the last item of the array into the callback.
return cb(arr[arr.length-1]);
}
last(items, console.log);

function sumNums(x, y, cb) {
// sumNums adds two numbers (x, y) and passes the result to the callback.
return cb(x + y);
}
sumNums(3, 4, console.log);

function multiplyNums(x, y, cb) {
// multiplyNums multiplies two numbers and passes the result to the callback.
return cb(x * y);
}
multiplyNums(3, 7, console.log);

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 checkItem = list.filter(specificItem => specificItem === item)[0];
return cb(checkItem === item)
}
contains('yo-yo', items, console.log);

/* STRETCH PROBLEM */

Expand Down
4 changes: 3 additions & 1 deletion assignments/closure.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
// 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.

let closure = 'This one right here';
printClosure = () => closure;
console.log(printClosure());

/* STRETCH PROBLEMS, Do not attempt until you have completed all previous tasks for today's project files */

Expand Down