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
42 changes: 38 additions & 4 deletions assignments/array-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,28 +56,62 @@ 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 = [];
runners.forEach(function(runner) {
return fullName.push(`${runner.first_name} ${runner.last_name}`)
})
console.log(fullName);

// ==== 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);
runners.map(function (names){
return allCaps.push(`${names.first_name.toUpperCase()} ${names.last_name.toUpperCase()}`);
})
console.log(allCaps);

// ==== 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);
runners.filter(function (size) {
if (size.shirt_size === "L") {
largeShirts.push(`${size.first_name} ${size.last_name}`)
}

})
console.log(largeShirts);

// ==== 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 = [];
let ticketPriceTotal = runners.reduce(function (acc, total){
return acc + total.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

//return everyones name and email
let nameAndEmail = []
runners.forEach(function(emails){
return nameAndEmail.push(`${emails.first_name} ${emails.last_name} : ${emails.email}`)
})

console.log(nameAndEmail);
// Problem 2
const bigSpenders = runners.filter((mula) =>{
return mula.donation > 250;
});

console.log(bigSpenders)
// Problem 3

// Problem 3
const longestName = runners.reduce(function (a, b) {
if (a.first_name > b.first_name ) {
return a.first_name.length
} else {
return b.first_name.length
}
} )
console.log(longestName)
38 changes: 28 additions & 10 deletions assignments/callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,48 @@ 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(leng) {
console.log(len);
});

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

last(items, function(end){
console.log(end)
})

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

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

multiplyNums(39, 5, function(multiply){
console.log(multiply);
})


function contains(item, list, cb) {
return cb(item === list)
}
contains('Pencil', items, function (x){
console.log(x)
} )
// contains checks if an item is present inside of the given array/list.
// Pass true to the callback if it is, otherwise pass false.
}


/* STRETCH PROBLEM */

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


25 changes: 19 additions & 6 deletions assignments/closure.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
// ==== Challenge 1: Write your own closure ====
// Write a simple closure of your own creation. Keep it simple!
function howOld (){
const age = 27;
console.log(`I am ${age}`)

function ageAndBirth (){
const dob = 'July 25, 1991';
console.log(`I am ${age} and was born on {dob}`)
}
}

howOld();

// ==== Challenge 2: Create a counter function ====
const counter = () => {
// Return a function that when invoked increments and returns a counter variable.
};
// Example usage: const newCounter = counter();
// newCounter(); // 1
// newCounter(); // 2
const counter = (function(count) {

return function() {
return count += 1;
}
}(0));

counter();


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

Expand Down