Skip to content

Jensen koch #778

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
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
20 changes: 19 additions & 1 deletion assignments/array-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,39 @@ 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(runner => {
fullNames.push(`${runner.first_name} ${runner.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 = [];

runners.map((runners, index) => {
firstNamesAllCaps[index] = runners.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(runners => runners.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 = [];

ticketPriceTotal = runners.reduce((totalValue, runners) => {
return totalValue + runners.donation;
}, 0);

console.log(ticketPriceTotal);

// ==== Challenge 5: Be Creative ====
Expand Down
42 changes: 38 additions & 4 deletions assignments/callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,60 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];
*/


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

function last(arr, cb) {
const getLength = (arr, cb) => {
cb(arr.length);
};
getLength(items, length => {
console.log(`The length of the array is ${length}.`);
});

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

last(items, lastItem => {
console.log(`The last item in the array is ${lastItem}`);
});

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

sumNums(3, 5, function(sumNums){
console.log(sumNums);
})

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

multiplyNums(6, 7, function(multiplyNums){
console.log(multiplyNums);
})

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.includes(item)){
return cb(true);
}
return cb(false);
contains(3,[1,2,3],function(success){
if(success){
return "true"
}
return "false"
})
}
contains('Notebook', items, function(contains){
console.log(contains);
})


/* STRETCH PROBLEM */

Expand Down
13 changes: 13 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 dogs = () => {
let dogNumber = 0;
return function() {
dogNumber = dogNumber + 1;
return dogNumber;
}
};

const moreDogs = dogs();
console.log(moreDogs());
console.log(moreDogs());
console.log(moreDogs());
console.log(moreDogs());

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

Expand Down