Reputation: 69
In this case, I'm making a sum of the object and its working just as I wanted to, the problem is the following message:
Expected to return a value in arrow function array-callback-return
Here is the code:
data.map((current,index, array) => {
const prevVisitors = array[index - 1 ] ? array[index - 1].visitors : 0
current.visitors += prevVisitors
})
What should I use as a return statement if there is nothing to be returned(Since it's only a modification of the props)? And in what cases this error is useful?
Upvotes: 0
Views: 1217
Reputation: 362
Your code should be
data.map((current,index, array) => {
const prevVisitors = array[index - 1 ] ? array[index - 1].visitors : 0
return current.visitors += prevVisitors
})
Upvotes: 1