From 408334380e9ff49cacf0cba22ff0fe1ed31d4b03 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Wed, 2 Apr 2025 19:07:53 +0300 Subject: [PATCH] Use Object methods when possible Signed-off-by: XhmikosR --- scripts/js/index.js | 8 +++--- scripts/js/queries.js | 52 +++++++++++------------------------- scripts/js/utils.js | 61 ++++++++++++++++--------------------------- 3 files changed, 42 insertions(+), 79 deletions(-) diff --git a/scripts/js/index.js b/scripts/js/index.js index a6477121..e45602f9 100644 --- a/scripts/js/index.js +++ b/scripts/js/index.js @@ -485,10 +485,10 @@ function labelWithPercentage(tooltipLabel, skipZero = false) { // Sum all queries for the current time by iterating over all keys in the // current dataset let sum = 0; - const keys = Object.keys(tooltipLabel.parsed._stacks.y); - for (let i = 0; i < keys.length; i++) { - if (tooltipLabel.parsed._stacks.y[i] === undefined) continue; - sum += Number.parseInt(tooltipLabel.parsed._stacks.y[i], 10); + for (const value of Object.values(tooltipLabel.parsed._stacks.y)) { + if (value === undefined) continue; + const num = Number.parseInt(value, 10); + if (num) sum += num; } let percentage = 0; diff --git a/scripts/js/queries.js b/scripts/js/queries.js index 0fffa457..209d7c19 100644 --- a/scripts/js/queries.js +++ b/scripts/js/queries.js @@ -416,12 +416,7 @@ function addSelectSuggestion(name, dict, data) { } // Add data obtained from API - for (const key in data) { - if (!Object.hasOwn(data, key)) { - continue; - } - - const text = data[key]; + for (const text of Object.values(data)) { obj.append($("