From 3d866e343b37941052720053c2f16321146a4677 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Wed, 31 Mar 2021 22:51:32 +0200 Subject: [PATCH] =?UTF-8?q?Simplification=20calcul=20de=20difficult=C3=A9?= =?UTF-8?q?=20alchimie?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- module/rdd-alchimie.js | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/module/rdd-alchimie.js b/module/rdd-alchimie.js index 6ceff48f..4fac68ac 100644 --- a/module/rdd-alchimie.js +++ b/module/rdd-alchimie.js @@ -44,20 +44,13 @@ export class RdDAlchimie { } /* -------------------------------------------- */ - static getDifficulte( aspects ) { - let aspectsArray = aspects.split('-'); - let diff = 0; - let nbDifferent = 0; - let aspectsHash = {} - for (let colconst of aspectsArray) { - if ( aspectsHash[colconst] ){ // Deja present, augmente difficultĂ© de 1 - diff -= 1; - } else { - nbDifferent++; - aspectsHash[colconst] = colconst; // Keep track - } + static getDifficulte(aspects) { + let elements = aspects.split('-'); + let composantes = elements.length; + let distincts = Object.keys(Misc.classifyFirst(elements, it => it)).length; + if (distincts == 1) { + composantes--; } - diff = diff - ((nbDifferent>1) ? nbDifferent : 0); // Ca doit marcher .... - return Math.min(0, diff); // Pour ĂȘtre sur + return Math.min(0, -composantes); } }