From 33aa593e9d77037218060d22e2a4c9008e8665aa Mon Sep 17 00:00:00 2001 From: Jean-Christophe Engel Date: Fri, 14 Jun 2024 10:10:33 +0200 Subject: [PATCH] =?UTF-8?q?tri.js=20g=C3=A9n=C3=A9ralisation=20tri=20par?= =?UTF-8?q?=20num=C3=A9ro=20(croissant/d=C3=A9croissant)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tri.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tri.js b/tri.js index 46b073f..af263af 100644 --- a/tri.js +++ b/tri.js @@ -9,7 +9,8 @@ function trierNumeros(tnumeros, tnoms, croissant = true) o.nom = tnoms[i]; tab.push(o); } - tab.sort((a, b) => { return a.numero - b.numero; }); + ordre = croissant ? 1 : -1; + tab.sort((a, b) => { return ordre * (a.numero - b.numero); }); return tab; }