From 609962f37aa69bceadef2932b538e52bc20f62cb Mon Sep 17 00:00:00 2001 From: William Lewis Date: Tue, 27 Jun 2023 08:27:40 -0500 Subject: [PATCH] Added sorting of accounts based on alloc priority --- index.html | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/index.html b/index.html index 1e1c268..54b53c5 100644 --- a/index.html +++ b/index.html @@ -76,6 +76,8 @@ document.getElementById("budget-table").innerHTML = header; + jsonData.body.sort(allocSort); + for (const item of jsonData.body) { summation += Number(item.balance); @@ -119,6 +121,24 @@ } } + function allocSort(a, b) { + if (a.notes != null && b.notes != null) { + let astr = a.notes.split('_')[1]; + let bstr = b.notes.split('_')[1]; + + if (astr == "MAIN") { + return -1; + } else if (bstr == "MAIN") { + return 1; + } else { + return Number(astr) - Number(bstr); + } + } else { + console.log("ERROR: alloc object doesn't have notes"); + return 0; + } + } + function addToTransactionTable(jsonData) { let header = "" + "ID"