Jonathan Heinz - #425
Conversation
| } | ||
|
|
||
| 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")); |
There was a problem hiding this comment.
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);There was a problem hiding this comment.
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}`)); |
There was a problem hiding this comment.
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) | ||
| }); |
There was a problem hiding this comment.
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)
});|
|
||
| console.log("\n"); | ||
|
|
||
| const newerCounter = counterFactory(); |
There was a problem hiding this comment.
newerCounter is a very good variable name; it's definitely among the greatest of the greats.
| }, | ||
| decrement: function() { | ||
| console.log(--counter); | ||
| } |
There was a problem hiding this comment.
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)
No description provided.