Skip to content

Create Variable Using Reduce Array Method#19

Open
ASPhillips8 wants to merge 2 commits into
learn-co-curriculum:masterfrom
ASPhillips8:reduce-array-asp
Open

Create Variable Using Reduce Array Method#19
ASPhillips8 wants to merge 2 commits into
learn-co-curriculum:masterfrom
ASPhillips8:reduce-array-asp

Conversation

@ASPhillips8

Copy link
Copy Markdown

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

Comment thread index.js
const batteryBatches = [4, 5, 3, 4, 4, 6, 5];

// Code your solution here
const totalBatteries = batteryBatches.reduce((battery, currentTotal) => battery + currentTotal, 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.

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