From 97190cec5d9144a535249e1490cdc61efbd54587 Mon Sep 17 00:00:00 2001 From: nicola Date: Sun, 17 Dec 2023 18:13:16 +0100 Subject: [PATCH] commentsArray sorted --- js/cesareBrowse.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/js/cesareBrowse.js b/js/cesareBrowse.js index a83fa9a..2eef0db 100644 --- a/js/cesareBrowse.js +++ b/js/cesareBrowse.js @@ -743,7 +743,24 @@ function resetFrasi(){ commentsArray.forEach(removeHtmlTags2) //console.log("Array dopo") - //console.log(commentsArray) + //console.log(commentsArray) + //commentsArray.sort(function(a, b){return a.verso - b.verso}); + var numVerso1; + var numVerso2; + + commentsArray.sort((p1, p2) => { + numVerso1 = p1.verso; + numVerso2 = p2.verso; + numVerso2 = numVerso2.replaceAll("_",""); + numVerso1 = numVerso1.replaceAll("_",""); + numVerso2 = parseInt(numVerso2); + numVerso1 = parseInt(numVerso1); + + if (numVerso1 < numVerso2) return -1; + if (numVerso1 > numVerso2) return 1; + return 0; + }); + console.log("Array dopo") } /* Luca: removeHtmlTags2 e' la versione compatta di removeHtmlTags*/