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
52 changes: 51 additions & 1 deletion assignments/array-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,78 @@ 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(function (currentValue, index) {
fullNames.push(`${currentValue.first_name} ${currentValue.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 = [];

firstNamesAllCaps = runners.map(function (currentValue, index) {
return currentValue.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(function (currentValue, index) {
return currentValue.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(function (accum, currentValue) {
return accum + 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
// The event was sponsored by multiple companies. WordTune withdrew their sponsorship after the event's conclusion. Sum up the donations from WordTune employees so the funds can be rerouted and pay dividends elsewhere.
let wordTuneDonations = 0;

wordTuneDonations = runners.filter(function (currentValue, index) {
return currentValue.company_name === "Wordtune";
}).reduce(function (accum, currentValue) {
return accum + currentValue.donation;
}, 0);

console.log(wordTuneDonations);

// Problem 2
// A potential supplier is requesting the above shirt size data to be sent to them for review. Problem is, their systems can only interpret lowercase alphanumeric characters.

let shirtSizesLower = [];

shirtSizesLower = runners.map(function (currentValue, index) {
return currentValue.shirt_size.toLowerCase();
});

console.log(shirtSizesLower);

// Problem 3
// The event's coordinators would like to create a 'donor titan' board for display next year. Showboaters. Return the names of all individuals that donated 200.00USD or more.

let donorTitans = [];

donorTitans = runners.filter(function (currentValue) {
return currentValue.donation > 200;
}).map(function (currentValue) {
return currentValue.first_name;
});

// Problem 3
console.log(donorTitans);
26 changes: 26 additions & 0 deletions assignments/callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,50 @@ 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);
}

function shoutResult(result) {
return `RESULT OF TEST IS ${result}!`;
}

test1 = getLength(items, shoutResult);
console.log(test1);

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

test2 = last(items, shoutResult);
console.log(test2);


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

test3 = sumNums(3, 7, shoutResult);
console.log(test3);

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

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.
return cb(list.includes(item));
}
test5 = contains('Gum', items, shoutResult);
console.log(test5);

test6 = contains("Six hundred tons of anti-matter", items, shoutResult);
console.log(test6);

/* STRETCH PROBLEM */

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

//global
const currency = "gold";

console.log(`The global currency is ${currency}.`);

function wakandagea() {
let countryCurrency = "dollar";

console.log(`The ${currency} of WakandaGea is ${countryCurrency}!`);

function archKansas(stateCurrency) {

console.log(`The ${currency} of Arch-Kansas is not ${countryCurrency}, but ${stateCurrency}!`);

function dimmsDale(townCurrency) {

console.log(`The ${currency} of Dimmsdale is neither ${countryCurrency} nor ${stateCurrency}, but the one and only ${townCurrency.toUpperCase()}!!!`);
} //This closes the town
dimmsDale("DimmaDollar");
}
archKansas("Freedom Unit");
}
wakandagea();

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

Expand Down