From c66259504e5e7ac240d4948135e74243695de75e Mon Sep 17 00:00:00 2001 From: Guilherme-NL Date: Fri, 17 Nov 2023 09:13:19 -0300 Subject: [PATCH] refactor: remove reduce and add Math.max to find the highest position --- app/assets/javascripts/models/beta/story.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/models/beta/story.js b/app/assets/javascripts/models/beta/story.js index bf6add078..d171169f0 100644 --- a/app/assets/javascripts/models/beta/story.js +++ b/app/assets/javascripts/models/beta/story.js @@ -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; };