Skip to content

Addison Stavlo - Project Complete - #430

Open
Addison-Stavlo wants to merge 5 commits into
bloominstituteoftechnology:masterfrom
Addison-Stavlo:master
Open

Addison Stavlo - Project Complete#430
Addison-Stavlo wants to merge 5 commits into
bloominstituteoftechnology:masterfrom
Addison-Stavlo:master

Conversation

@Addison-Stavlo

Copy link
Copy Markdown

@ashwins93 ashwins93 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Great job as always hitting all the stretch goals. I'd recommend you to work on some hard code challenges to test your new knowledge of arrow functions and built-in functions. Git commits look great.

// ==== 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( item => fullName.push(item.first_name + ' ' + item.last_name));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good use of arrow functions to keep the code terse.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can you guess what happens if you did not provide the second argument to reduce? What is the output? Does it throw an error?


// Problem 1
// change everyones first name to their last name!?
runners.forEach( item => item.first_name = item.last_name);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Don't you think map is better suited for this job to keep the original array intact and thereby not affecting the code that follows this? How would you achieve the same task with map?

// Problem 3 No newline at end of file
// Problem 3
// new array with list of people of shirt size L who donated less than $10, or size XL who donated less than $20
let largeShirtsSmallDonations = runners.filter(item => (item.shirt_size === "L" && item.donation < 10) || (item.shirt_size === "XL" && item.donation < 20));

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 the most useful use of filter for the company that gives the shirts.

Comment thread assignments/callbacks.js
// Do not mutate the original array.
let newArray = [];
for (i=0;i<array.length;i++){
if(newArray.indexOf(array[i]) === -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.

Array#includes might help you shorten your code here.

Comment thread assignments/callbacks.js
// 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 newArray = array.map(item => 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.

Array#slice will help you produce a shallow copy of the array. This code is perfectly valid too.

Comment thread assignments/closure.js
const counter = () => {
// Return a function that when invoked increments and returns a counter variable.
let count = 0;
return () => ++count;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

That's a really cool one-liner function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants