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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5501
}
17 changes: 17 additions & 0 deletions assignments/array-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,38 @@ const runners = [
let fullNames = [];
console.log(fullNames);

runners.forEach (function (runner) {
return fullNames.push(`${runner.first_name} ${runner.last_name}`)
})


// ==== 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);

runners.map (function (runner) {
return firstNamesAllCaps.push(`${runner.first_name.toUpperCase()}`);
})

// ==== 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);

runnersLargeSizeShirt = runners.filter (function (runner) {
return runner.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;
console.log(ticketPriceTotal);

ticketPriceTotal = runners.reduce((total, runner) => {
return total + 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.

Expand Down
10 changes: 10 additions & 0 deletions assignments/callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,33 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];

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

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

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

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

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.
for(let i = 0; i < list.length; i++) {
if (list[i] === item) {
return cb(true);
}
}
return cb(false);
}

/* STRETCH PROBLEM */
Expand Down
9 changes: 9 additions & 0 deletions assignments/closure.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@
// 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.
function totalSum() {
var number = 16;
function displaySum() {
return (12 + number);
}
return displaySum;
}

var myFunc = totalSum();
myFunc();

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

Expand Down