Skip to content

Conversation

@ASPhillips8
Copy link

Use reduce array method to get accumulated sum of batteries. Refactor code with arrow function to get more familiar.

const batteryBatches = [4, 5, 3, 4, 4, 6, 5];

// Code your solution here
const totalBatteries = batteryBatches.reduce((battery, currentTotal) => battery + currentTotal, 0);

Choose a reason for hiding this comment

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

This works! But to be more accurate, you would flip the argument names.

Suggested change
const totalBatteries = batteryBatches.reduce((battery, currentTotal) => battery + currentTotal, 0);
const totalBatteries = batteryBatches.reduce((currentTotal, battery) => battery + currentTotal, 0);

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