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

226 changes: 226 additions & 0 deletions .idea/workspace.xml

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

36 changes: 26 additions & 10 deletions assignments/array-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,29 +55,45 @@ const runners = [{"id":1,"first_name":"Charmain","last_name":"Seiler","email":"c

// ==== 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 into a new array called fullName.
let fullName = [];
console.log(fullName);

function loopNamesFE(){
// let fullName = runners.map((person) => { return {'first_name': person.first_name, 'last_name': person.last_name} } );
let fullName =[];
runners.forEach(person => fullName.push(person.first_name +', '+ person.last_name));
console.log(fullName);
}
console.log(loopNamesFE());
// ==== Challenge 2: Use .map() ====
// The event director needs to have all the runner's first names converted to uppercase because the director BECAME DRUNK WITH POWER. Convert each first name into all caps and log the result
let allCaps = [];
console.log(allCaps);
function capsNames(){
let allCaps = runners.map((person) => { return {'first_name': person.first_name.toUpperCase(), 'last_name': person.last_name, 'email': person.email, 'shirt_size': person.shirt_size, 'company_name': person.company_name, 'donation': person.donation} })
console.log(allCaps);
}
console.log(capsNames());

// ==== Challenge 3: Use .filter() ====
// The large shirts won't be available for the event due to an ordering issue. Get a list of runners with large sized shirts so they can choose a different size. Return an array named largeShirts that contains information about the runners that have a shirt size of L and log the result
let largeShirts = [];
console.log(largeShirts);
function bigSize(){
let largeShirts = runners.filter((person) => person.shirt_size === 'L');
console.log(largeShirts);
}
console.log(bigSize());

// ==== Challenge 4: Use .reduce() ====
// The donations need to be tallied up and reported for tax purposes. Add up all the donations into a ticketPriceTotal array and log the result
let ticketPriceTotal = [];
console.log(ticketPriceTotal);
function allDonations(){
let ticketPriceTotal = runners.reduce( ( (total, person) => total += person.donation), 0);
console.log(ticketPriceTotal);
}
console.log(allDonations());

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

function loopNamesMap(){
let fullName = runners.map((person) => { return {'first_name': person.first_name, 'last_name': person.last_name} } );
console.log(fullName);
}
// Problem 3
11 changes: 10 additions & 1 deletion assignments/callbacks.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Create a higher order function and invoke the callback function to test your work. You have been provided an example of a problem and a solution to see how this works with our items array. Study both the problem and the solution to figure out the rest of the problems.

const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];
const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum', 'Gum'];

/*

Expand All @@ -27,23 +27,28 @@ 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 last(arr, cb) {
// last passes the last item of the array into the callback.
return cb(arr[length-1]);
}

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

function multiplyNums(x, y, cb) {
// multiplyNums multiplies two numbers and passes the result to the callback.
return 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.
return cb(list.includes(item));
}

/* STRETCH PROBLEM */
Expand All @@ -52,4 +57,8 @@ 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.
// let removeDuplicates = array.filter( (i,j) => { console.log(i,j,array.indexOf(i),array.indexOf(i) === j); return array.indexOf(i) === j});
let removeDuplicates = array.filter( (value, index) => array.indexOf(value) === index );
return cb(removeDuplicates);
}
console.log(removeDuplicates(items, (arr)=> console.log(arr)));
Loading