Link-/pr-comment

Bad use of `reduce`

elibarzilay opened this issue · 0 comments

pr-comment/index.js

Lines 25 to 30 in d402b9c

diffData = changedFiles.reduce((acc, file) => {
acc.additions += file.additions;
acc.deletions += file.deletions;
acc.changes += file.changes;
return acc;
}, diffData);

Since you're using it for demonstrating stuff, then JFYI, this use of .reduce is very broken: you're passing in diffData, and then you mutate its contents instead of creating a new data object and keep passing the exact same object...

So my guess is that you could simplify this whole thing to:

 changedFiles.forEach(file => { 
   acc.additions += file.additions; 
   acc.deletions += file.deletions; 
   acc.changes += file.changes; 
 });

(Yeah, re-editing the video is impractical, but still, JFYI.)