Skip to content
Open

v1 #397

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: 14 additions & 6 deletions assignments/array-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const runners = [{"id":1,"first_name":"Charmain","last_name":"Seiler","email":"c
{"id":7,"first_name":"Kathie","last_name":"Majury","email":"[email protected]","shirt_size":"3XL","company_name":"Zoomcast","donation":261},
{"id":8,"first_name":"Tanner","last_name":"Branton","email":"[email protected]","shirt_size":"2XL","company_name":"Realmix","donation":28},
{"id":9,"first_name":"Sarina","last_name":"Lasham","email":"[email protected]","shirt_size":"XL","company_name":"Gigashots","donation":110},
{"id":10,"first_name":"Bertie","last_name":"Lonergan","email":"[email protected]","shirt_size":"3XL","company_name":"Skinte","donation":62},
{"id":10,"first_name":"Bertie","last_name":"Lonergan","email":"blonergan9@issuu. com","shirt_size":"3XL","company_name":"Skinte","donation":62},
{"id":11,"first_name":"Trevor","last_name":"Studd","email":"[email protected]","shirt_size":"S","company_name":"Cogidoo","donation":76},
{"id":12,"first_name":"Malachi","last_name":"Okeshott","email":"[email protected]","shirt_size":"M","company_name":"DabZ","donation":91},
{"id":13,"first_name":"Berget","last_name":"Logsdail","email":"[email protected]","shirt_size":"M","company_name":"Mymm","donation":9},
Expand Down Expand Up @@ -55,22 +55,30 @@ 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 = [];
let fullName = runners.map(function(item) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forEach was supposed to be used here instead of map.

return `${item.first_name} ${item.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);
let allCaps = runners.map(function(item) {
return item[i].first_name.toUpperCase();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for i which is undefined anyway.

});
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 = [];
let largeShirts = runners.filter(function(item) {
return item.shirt_size === 'L';
});
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((total, item) => total += item.donation, 0);

console.log(ticketPriceTotal);

// ==== Challenge 5: Be Creative ====
Expand Down
23 changes: 22 additions & 1 deletion assignments/callbacks.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
// Create a callback function and invoke the 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'];
function firstItem(arr, cb) {
return cb(arr[0]);
};
firstItem(items, function(first) {
console.log(first);
})

/*

Expand All @@ -24,23 +30,38 @@ 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(item, function(arrayLength) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for that line of code.

console.log(arrayLength)
})

}

function last(arr, cb) {
// last passes the last item of the array into the callback.
return cb(arr.length-1)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be cb(arr[arr.length -1])

}

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

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

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.

}

/* STRETCH PROBLEM */
Expand Down
8 changes: 7 additions & 1 deletion assignments/closure.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
// ==== Challenge 1: Write your own closure ====
// Write a simple closure of your own creation. Keep it simple!

function mathProb() {
let x = 3;
let y = 2;
return x+y;
}

// ==== Challenge 2: Create a counter function ====
const counter = () => {
let counterVar = 0 += x;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is invalid left hand side assignment.

return counterVar;
// Return a function that when invoked increments and returns a counter variable.
};
// Example usage: const newCounter = counter();
Expand Down