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
31 changes: 20 additions & 11 deletions assignments/array-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,29 +57,38 @@ 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);

let fullNames = runners.map((runner) => runner.first_name + " " + runner.last_name)
console.log(fullNames.sort());

// ==== 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 = [];
let firstNamesAllCaps = runners.map((runner) => runner.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);

let runnersLargeSizeShirt = runners.filter((runner) => runner.shirt_size === 'L')
console.log(JSON.stringify(runnersLargeSizeShirt, null, 4));
// ==== 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.map((runner) => runner.donation);
let reducer = (accumulator, currentValue) => accumulator + currentValue;
console.log(ticketPriceTotal.reduce(reducer));

// ==== 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 1: List runners' companies
let companyNames = runners.map((runner) => runner.company_name)
console.log(companyNames);


// Problem 2: Donations per company
let companyDonate = runners.map((runner) => runner.company_name + " " + runner.donation)
console.log(companyDonate);

// Problem 3
// Problem 3: All runners with size M shirts
let mShirt = runners.filter((shirt) => shirt.shirt_size === 'M')
console.log(JSON.stringify(mShirt, null, 4));
2 changes: 1 addition & 1 deletion assignments/callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];
*/


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

Expand Down
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.

let num1 = Number(prompt('Pick a number'));
let num2 = Number(prompt('Pick a number'));

function subtractNums(num1, num2) {
return num1 - num2;
}
console.log(subtractNums(num1, num2));


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

Expand Down