Skip to content

Commit

Permalink
refactor: remove reduce and add Math.max to find the highest position
Browse files Browse the repository at this point in the history
  • Loading branch information
Guilherme-NL authored and GabrielRMuller committed Aug 12, 2024
1 parent 857203c commit c662595
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions app/assets/javascripts/models/beta/story.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,8 @@ export const getHighestNewPosition = stories => {
if (stories.length === 1) {
return 1;
}
const highestPositionValue = stories
.filter(story => story.newPosition !== null)
.reduce((acc, story) => {
return story.newPosition > acc ? story.newPosition : acc;
}, stories[0].newPosition);
const storiesNewPosition = stories.map(story => story.newPosition);
const highestPositionValue = Math.max(...storiesNewPosition);

return highestPositionValue + 1;
};
Expand Down

0 comments on commit c662595

Please sign in to comment.