Reputation: 39018
My code (which works):
const calculateBalance = (coins) => {
console.log('coins', coins);
return coins.reduce((bal, coin) => (bal += parseInt(coin.balance)), 0);
};
Basically I just want to add up all the coin balances in my portfolio, however I'm getting an eslint error.
Arrow function should not return assignment.
Googling I found this: https://eslint.org/docs/rules/no-return-assign
One of the interesting, and sometimes confusing, aspects of JavaScript is that assignment can happen at almost any point. Because of this, an errant equals sign can end up causing assignment when the true intent was to do a comparison. This is especially true when using a return statement.
Here they have an example of what to do:
function doSomething() {
return (foo = bar + 2);
}
However that is what I implemented, but eslint is still complaining... is there a way to update my code block above to make it pass?
Upvotes: 0
Views: 1363