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
12 changes: 6 additions & 6 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 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 `<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 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 `<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 Down
53 changes: 52 additions & 1 deletion assignments/array-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,28 +56,79 @@ 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 = [];

runners.forEach(function(item){
fullName.push(item.first_name + " " + item.last_name);
}
);
console.log(fullName);

// ==== 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 = [];

runners.map(function(item){


allCaps.push(item.first_name.toUpperCase())
});
console.log(allCaps);

// ==== 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 = [];

runners.filter(function(item){
if(item.shirt_size === "L"){;
largeShirts.push(item.first_name + " " + item.last_name)
}})

console.log(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 = [];

ticketPriceTotal = runners.reduce(function(accumulator, currentValue){
return accumulator + currentValue.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
//We need company names for a sponsor banner, collect all of the company names and log the result.

let companyNames = [];

runners.forEach(function(item){
companyNames.push(item.company_name);
}
);
console.log(companyNames);


// Problem 2
//We need the runners names and email addresses to add to our mailing list. Compile a list and log the results.

let emailAddresses = [];

runners.forEach(function(item){
emailAddresses.push(`${item.first_name} ${item.last_name}, email: ${item.email}`);
}
);
console.log(emailAddresses);

// Problem 3

//We are generating thank you notes to all the attendees of the run. Take the note and populate the information with the given data and log the results.

let thankYou = [];

// Problem 3
runners.forEach(function(item){
thankYou.push(`Hi ${item.first_name}! We would like to thank you for attending the 5th Annual 5k Fun Run. We appreciate the donation of $${item.donation}.00 from your company, ${item.company_name}. We hope to see you next year!`);
}
);
console.log(thankYou);
66 changes: 59 additions & 7 deletions assignments/callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];
return cb(arr[0]);
}

// Function invocation
firstItem(items, function(first) {
console.log(first)
});
Expand All @@ -26,30 +25,83 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];


function getLength(arr, cb) {
// getLength passes the length of the array into the callback.
// getLength passes the length of the array into the callback.
return cb(arr.length);
}

getLength(items, function(long){
console.log(long)
});





function last(arr, cb) {
// last passes the last item of the array into the callback.

//DO I WANT THE ITEM OR THE NUMBER OF THE ITEM RETURNING?
return cb(arr.length-1);
}
last(items, function(end){
console.log(items[end])
})

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

sumNums(5,4, function(sumthing){
console.log(sumthing)
})


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





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.

list.forEach(element => {
if(element === item){
cb(true)
} else{
cb(false)
}
});
}

contains("Gum", items, function(result){
if(result === true){
console.log("I found a match!");
}})












/* 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.
}
// 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.
// }
7 changes: 7 additions & 0 deletions assignments/closure.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
// ==== Challenge 1: Write your own closure ====
// Write a simple closure of your own creation. Keep it simple!
let location = "I'm taking over the world!"
function findMe(where){
console.log(where);
}

findMe(location);



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