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 .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/JavaScript-II.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 34 additions & 5 deletions assignments/array-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,57 @@ 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(fullName) {
return fullNames.push(`${fullName.last_name} ${fullName.first_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 = [];
//let firstNamesAllCaps = [];


const firstNamesAllCaps = runners.map(function(fullName){
return fullName.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 = [];
// let runnersLargeSizeShirt = [];

const runnersLargeSizeShirt = runners.filter(function(shirtSize){
return shirtSize.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;
// let ticketPriceTotal = 0;

const ticketPriceTotal = runners.reduce(function(taxes, donations){
return taxes + donations.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

const quantityOfShirts = runners.filter(function(size){
return size.shirt_size === "XS";
});
console.log(quantityOfShirts.length);
// Problem 2
const largeDonation = runners.filter(function(amount){
return amount.donation > 200;
});
console.log(largeDonation);

// Problem 3

// Problem 3
const allRunners = runners.map((people) => {
return {'id': people.id, 'name': people.first_name + " " + people.last_name};
});
console.log(allRunners);
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);
}
getLength(items, function(length){
console.log(length);
});

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

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


function multiplyNums(x, y, cb) {
// multiplyNums multiplies two numbers and passes the result to the callback.
return cb(x, y)
}
multiplyNums(9, 4, function(num1, num2) {
console.log(num1 * num2);
});

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.
if (list.indexOf(item) === -1) {
return cb(`"${item}" is not in the array`);
}
else {
return cb(`"${item}" is in the array`);
}
}
contains("Flower", items, function(listItem) {
console.log(listItem);
});

/* STRETCH PROBLEM */

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

const calendar = 'year';
function returnNum(){
const calendarMP = 'months';
const calendarMS = 'month';
console.log(`There are 12 ${calendarMP} in a ${calendar}.`);
function returnNum(){
const calendarW = 'weeks'
console.log(`There are 4 ${calendarW} in a ${calendarMS}.`);
}
returnNum();
}
returnNum();


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

Expand All @@ -16,8 +29,15 @@ const counterMaker = () => {
// NOTE: This `counter` function, being nested inside `counterMaker`,
// "closes over" the `count` variable. It can "see" it in the parent scope!
// 3- Return the `counter` function.
let count = 0;
return () => ++count;
};
// Example usage: const myCounter = counterMaker();
const myCounter = counterMaker();
console.log(myCounter());
console.log(myCounter());
console.log(myCounter());

// myCounter(); // 1
// myCounter(); // 2

Expand Down