Skip to content

David Freitag#449

Open
freitagdavid wants to merge 5 commits intobloominstituteoftechnology:masterfrom
freitagdavid:master
Open

David Freitag#449
freitagdavid wants to merge 5 commits intobloominstituteoftechnology:masterfrom
freitagdavid:master

Conversation

@freitagdavid
Copy link

No description provided.

Copy link

@johnoro johnoro left a comment

Choose a reason for hiding this comment

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

Great work!


getLength(items, function(length) {
console.log(length);
});
Copy link

Choose a reason for hiding this comment

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

You could forego the wrapping function and just use console.log as your callback here:

getLength(items, console.log);

then, because of return cb(arr.length) will pretty much equate to console.log(items.length)

.filter(item => item.company_name === company)
.map(item => item.donation)
.reduce((total, item) => total + item))
);
Copy link

@johnoro johnoro Oct 17, 2018

Choose a reason for hiding this comment

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

Here is an example of another approach to this problem:

const donationsByCompany = runners
  .reduce((acc, { company_name, donation }) => {
    if (acc.hasOwnProperty(company_name)) {
      acc[company_name] += donation;
      return acc;
    } else {
      return { ...acc, [company_name]: donation };
    }
  }, {});

using object destructuring and spread syntax.

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