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
50 changes: 40 additions & 10 deletions assignments/array-methods.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// A local community center is holding a fund raising 5k fun run and has invited 50 small businesses to make a small donation on their behalf for some much needed updates to their facilities. Each business has assigned a representative to attend the event along with a small donation.

// https://repl.it/@meltzerkyle/AstonishingAcademicDownload

// Scroll to the bottom of the list to use some advanced array methods to help the event director gather some information from the businesses.

const runners = [
Expand Down Expand Up @@ -58,28 +60,56 @@ 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 = [];
console.log(fullNames);

runners.forEach((runners) => {
fullNames.push(`${runners.first_name} ${runners.last_name}`)
});

console.table(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 = [];
console.log(firstNamesAllCaps);
let firstNamesAllCaps = runners.map((runners) => {
return runners.first_name.toUpperCase();
});

console.table(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);
let runnersLargeSizeShirt = runners.filter((runners) => {
return runners.shirt_size === "L";
});
console.table(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;
console.log(ticketPriceTotal);
let ticketPriceTotal = runners.reduce((ticketPriceTotal, runners) => {
return ticketPriceTotal += runners.donation;
}, 0);
console.log();
console.log(`Donations totaled to $${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 .map() Runner introduction statment
let introduction = runners.map((runners) => {
return (`Hello my name is ${runners.first_name} ${runners.last_name} and I work for ${runners.company_name}.`);
});

console.table(introduction);

// Problem 2
// Problem 2 .filter() donations larger than $100
let runnersLargedonation = runners.filter((runners) => {
return runners.donation >= 100;
});
console.table(runnersLargedonation);

// Problem 3
// Problem 3 .reduce() find the agerage of the total doantions
let Total = runners.reduce((Total, runners) => {
return Total += runners.donation;
}, 0);
let mean = Total / runners.length;
console.log();
console.log(`Donations mean is $${mean}.`);
37 changes: 37 additions & 0 deletions assignments/callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,29 +41,66 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];

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

getLength(items, (lengthOfList) => {
console.log(lengthOfList);
});

function last(arr, cb) {
// last passes the last item of the array into the callback.
cb(arr.length-1);
}

last(items, (lastItem) => {
console.log(lastItem);
});

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

sumNums(2,1, (sumItem) => {
console.log(sumItem);
});

function multiplyNums(x, y, cb) {
// multiplyNums multiplies two numbers and passes the result to the callback.
let multi = x * y;
cb(multi);
}

multiplyNums(3,4, (multiItem) => {
console.log(multiItem);
});

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 isPresent = false;
for(let i=0;i < list.length; i++) {

if(list[i] === item) {
isPresent = true;
break;
}
}

cb(isPresent);
}

contains("Gumm", items, (e) => {
console.log(e);
})

/* 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.

}
8 changes: 8 additions & 0 deletions assignments/closure.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
// that manipulates variables defined in the outer scope.
// The outer scope can be a parent function, or the top level of the script.

const name = "Jessica";

function returnName () {
return (`Hello my name is ${name}!`);
}

console.log(returnName());


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

Expand Down
1 change: 1 addition & 0 deletions assignments/tempCodeRunnerFile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@