From cb2d25c6251251dc374c42805839813ab577d20b Mon Sep 17 00:00:00 2001 From: hdinia <33469289+hdinia@users.noreply.github.com> Date: Thu, 23 Jan 2025 10:27:15 +0100 Subject: [PATCH] fix(ui): resolve sonar complexity warning --- webapp/src/services/utils/index.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/webapp/src/services/utils/index.ts b/webapp/src/services/utils/index.ts index 4c73f86c13..612a11e416 100644 --- a/webapp/src/services/utils/index.ts +++ b/webapp/src/services/utils/index.ts @@ -201,12 +201,8 @@ export const buildModificationDate = ( return duration.locale(language.substring(0, 2) === "fr" ? "fr" : "en").humanize(); }; -export const countAllChildrens = (tree: VariantTree): number => { - if (tree.children.length > 0) { - return tree.children.map((elm) => 1 + countAllChildrens(elm)).reduce((acc, curr) => acc + curr); - } - return 0; -}; +export const countDescendants = (tree: VariantTree): number => + tree.children.length ? tree.children.reduce((sum, child) => sum + 1 + countDescendants(child), 0) : 0; export const findNodeInTree = (studyId: string, tree: VariantTree): VariantTree | undefined => { if (studyId === tree.node.id) {