Skip to content

Jonathan Heinz - #425

Open
jheinz1999 wants to merge 6 commits into
bloominstituteoftechnology:masterfrom
jheinz1999:master
Open

Jonathan Heinz#425
jheinz1999 wants to merge 6 commits into
bloominstituteoftechnology:masterfrom
jheinz1999:master

Conversation

@jheinz1999

Copy link
Copy Markdown

No description provided.

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

Awesome work!

Comment thread assignments/callbacks.js
}

contains('Pencil', items, contained => contained ? console.log("Item is in array") : console.log("Item is not in array"));
contains('Pen', items, contained => contained ? console.log("Item is in array") : console.log("Item is not in array"));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You could make a named function for the callback that you use twice to reduce repetition; i.e.:

const logItemPresence = contained => contained 
  ? console.log("Item is in array") 
  : console.log("Item is not in array");
contains('Pencil', items, contained => logItemPresence);
contains('Pen', items, logItemPresence);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You could also shorten it by using console.log only once:

const logItemPresence = contained => console.log(
  contained 
    ? "Item is in array" 
    : "Item is not in array"
);
contains('Pencil', items, contained => logItemPresence);
contains('Pen', items, logItemPresence);

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

You could use object destructuring here:

 runners.forEach(({ first_name, last_name }) => fullName.push(`${first_name} ${last_name}`)); 

runners.forEach(item => {
if (!companies.includes(item.company_name))
companies.push(item.company_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.

Here is a good example of where object destructuring is nice for brevity since you're accessing the same key multiple times:

runners.forEach(({ company_name }) => {
  if (!companies.includes(company_name))
    companies.push(company_name)
});

Comment thread assignments/closure.js

console.log("\n");

const newerCounter = counterFactory();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

newerCounter is a very good variable name; it's definitely among the greatest of the greats.

Comment thread assignments/closure.js
},
decrement: function() {
console.log(--counter);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You could shorten these with arrow functions; for example:

decrement: () => {
  console.log(--counter);
}

or even

decrement: () => console.log(--counter);

although the last could be considered a no-no since you're not necessarily using that value that you're implicitly returning (but it's fine in this case, and JS will let you do it too)

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